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
#!/usr/bin/perl -w
use strict;
use CGI;
use CGI::Carp qw(fatalsToBrowser);
my $cgi = CGI->new();
print $cgi->header();
unless($cgi->param('id')){
print "<html><head><title>Logfile </title></head><body>\n";
print "<form action =\"/cgi-bin/comments.pl\" method=\"post\">\n";
print "<p><b> Logfilename eingeben </b> <br> \n";
print " <p> <input name =\"Logfilename\" size = \"40\" > </p> \n",
"<p> <input type='hidden' name =\"id\" value='1' > </p> \n";
print "<p> <input type = \"submit\" value = \"Ok\" > </p> \n";
print "</form>\n";
print "</body></html>\n";
exit(0);
}
my $a = "logfile-accesspoint-1.txt";
my $b = "logfile-accesspoint-2.txt";
my $file= $cgi->param("Logfilename");
if($file eq $a) {
logfile($a);
}
elsif($file eq $b) {
logfile($b);
}
sub logfile {
my ($file) = @_;
open(LOGFILE1, "<$file") or die "kann $f nicht oeffnen: $!\n";
while(<LOGFILE1>) {
print;
}
close LOGFILE1;
}
*) Der Vergleichsoperator bei Strings ist
eq
*) Man sollte immer versuchen, Dinge zusammenzufassen (wie hier die Subroutine)
*) Du musst ne Fallunterscheidung machen, ob das Formular abgesendet wurde oder ob das Formular angezeigt werden soll
*) Du solltest Dir im Wiki nochmal den Artikel zum Thema "use strict" durchlesen...