Leser: 21
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#!/usr/bin/perl
use CGI qw(:standard);
$name=$ENV{'REMOTE_USER'};
$dir="/Library/WebServer/Documents/$name";
chdir($dir) or die "$!huhu";
opendir (DIR, ".") or die "$!";
@folders = grep {/ome/} readdir DIR;
$c=0;
foreach $folder (@folders)
{
$c++;
}
if ($c==0)
{
print header;
print start_html('no data'),
h1('keine Daten vorhanden!'),
hr;
}
else
{
print header;
print start_html('Test'),
h1('test'),
start_form(
-name => 'main_form',
-method => 'POST',
-enctype => &CGI::URL_ENCODED,
-action => '/cgi-bin/link.cgi',
),
p,
"Ordner auswaehlen :",
p,
popup_menu('ordnermenu', [@folders]),
p,
submit
,
end_form,
hr;
if (param()) {
em(join(", ",param('ordnermenu'))),
, hr;
}
print end_html;
}
2010-10-22T19:50:20 gmafxWie kann ich in diesem Fall den Ordnernamen an das Skript "link.cgi" weitergeben?
Can't call method "redirect" on an undefined value at
1
2
3
4
5
6
7
8
9
#!/usr/bin/perl
use strict;
use warnings;
use CGI;[code]
my $query = new CGI;
print $query->redirect("http://localhost/cgi-bin/test2.cgi");
1
2
3
4
5
print "Status: 302 Found\n";
print "Location: $ucsc\n";
print "URI: <$ucsc>\n";
print "Content-type: text/html\r\n\r\n";
print "URL: $ucsc";
2010-10-23T12:17:32 gmafx
Ich bekomme in der Zeile, in der der redirect steht einen:
Code: (dl )Can't call method "redirect" on an undefined value at
$link enthält einen validen Link, den ich auch ausdrucken lassen kann. Diesen habe ich mir vorher zusammengebaut.
2010-10-22T19:50:20 gmafxCode: (dl )1
2
3
4
5
6
7
8
9
10@folders = grep {/ome/} readdir DIR;
$c=0;
foreach $folder (@folders)
{
$c++;
}
if ($c==0)
{
...
1 2 3
@folders = grep {/ome/} readdir DIR; if (! @folders) { # oder: if (scalar @folders == 0) ...
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64
#!/usr/bin/perl use CGI; use CGI::Carp qw(fatalsToBrowser); use strict; use warnings; my $link_cgi='/cgi-bin/link.cgi'; my $name=$ENV{'REMOTE_USER'}; my $dir="/Library/WebServer/Documents/$name"; # neue CGI Instanz erzeugen my $cgi=CGI->new(); # Verzeichnis auslesen opendir (my $dh, $dir) or die "ERROR OPENDIR: $!"; # hole alle Verzeichnisse (-d) die "ome" (/ome/) im namen haben und sortiere (sort) sie. my @folders = sort grep {/ome/ && -d "$dir/$_"} readdir($dh); closedir($dh); # kein Ordner gefunden if(!@folders) { print $cgi->header(), $cgi->start_html('no data'), $cgi->h1('keine Daten vorhanden!'), $cgi->hr; $cgi->end_html; } # nur ein ordner gefunnden elsif(@folders==1) { # url zusammensetzen: my $uri="$link_cgi?ordnermenu=$folders[0]"; print $cgi->redirect( -uri=>$uri, -nph=>1, -status=>302 ); } else { print $cgi->header(), $cgi->start_html('Test'), $cgi->h1('test'), $cgi->start_form( -name => 'main_form', -method => 'POST', -enctype => &CGI::URL_ENCODED, -action => $link_cgi, ), $cgi->p( "Ordner auswaehlen :" ), $cgi->p( $cgi->popup_menu('ordnermenu', [@folders]) ), $cgi->p( $cgi->submit() ), $cgi->end_form, $cgi->hr; if (my @ordner=$cgi->param('ordnermenu')) { print $cgi->em(join(", ",@ordner)), $cgi->hr; } print $cgi->end_html; }