Thread CGI-Taschenrechner bauen (11 answers)
Opened by frank1967 at 2012-04-14 11:49

frank1967
 2012-04-17 22:01
#157562 #157562
User since
2012-04-14
5 Artikel
BenutzerIn
[default_avatar]
Hallo Linuxer,

vielen Dank für die Antwort.
Das hat mir schon weitergeholfen.
Mein Script sieht jetzt folgendermaßen aus:

Code: (dl )
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
65
#!/Perl/bin/perl -w

use strict;
use warnings;

# einfaches Taschenrechnerprogramm
my $Zahl1
my $Zahl2
my $Rechenart
my $Ergebnis
read(STDIN, $input, $ENV{ 'CONTENT_LENGTH'});
my %Form; # Hash für Variablen
my @pairs = split( /&/, $input );
foreach my $pair ( @pairs ) {
my ($name, $value) = split(/=/, $pair);
$name =~ tr/+/ /;
$name =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$value =~ tr/+/ /;
$value =~ s/%([a-fA-F0-9][a-fA-F0-9])/pack("C", hex($1))/eg;
$Form{ $name } = $value;
}
# ab jetzt sind die eingelesenen CGI-Variablen in %Form drin

print "Content-type: text/html\n\n";
print "<html>";
print "<head>";
print "<title>Antwortseite des CGI-Programms</title>";
print "</head>";
print "<body>";
print "<p>";
print "<br>$Ergebnis</b>\n";

# Zahl 1
$Zahl1 = $Form{Zahl1};
# Zahl 2
$Zahl2 = $Form{Zahl2};

#Rechenart
$Rechenart = $Form{Rechenart};

if ( $Rechenart eq '+' )
{
$Ergebnis = $Zahl1 + $Zahl2;
}
elsif ( $Rechenart eq '-' )
{
$Ergebnis = $Zahl1 - $Zahl2;
}
elsif ( $Rechenart eq '*' )
{
$Ergebnis = $Zahl1 * $Zahl2;
}
elsif ( $Rechenart eq '/' )
{
$Ergebnis eq $Zahl1 / $Zahl2;
}
else
{
print "Diese Rechenart ist mir nicht bekannt!";
die;
#stirb - Programmabruch
}
print "Die Rechnung: $Zahl1 $Rechenart $Zahl2 = $Ergebnis";
print "</body>";
print "</html>";


Leider funktioniert es nicht und ich bekomme folgende Fehlermeldung:

Code: (dl )
1
2
3
4
5
6
7
8
9
10
11
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Premature end of script headers: Hausaufgabe2.pl
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] syntax error at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 8, near "$Zahl1\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] my "\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Global symbol "$Zahl2" requires explicit package name at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 9.\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Global symbol "$Zahl2" requires explicit package name at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 36.\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Global symbol "$Zahl2" requires explicit package name at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 43.\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Global symbol "$Zahl2" requires explicit package name at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 47.\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Global symbol "$Zahl2" requires explicit package name at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 51.\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Global symbol "$Zahl2" requires explicit package name at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 55.\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Global symbol "$Zahl2" requires explicit package name at C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl line 63.\r
[Tue Apr 17 21:49:18 2012] [error] [client 127.0.0.1] Execution of C:\\Apache Software Foundation\\Apache2.2\\cgi-bin\\Hausaufgabe2.pl aborted due to compilation errors.\r


Was besagen die Meldungen und wie kann man die Fehler beseitigen, ich weiß nicht mehr weiter.
Viele Grüße.
frank1967

View full thread CGI-Taschenrechner bauen