Leser: 23
perldoc -f sprintf
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
#!/usr/bin/perl -w use CGI::Carp qw(fatalsToBrowser); $daten = <>; @daten = split("",$daten); splice(@daten,3,5); shift@daten; splice(@daten,1,1); @zahl = @daten; pop @zahl; $zahl = join("",@zahl); @potenz = splice(@daten,1,1); $potenz = join("",@potenz); print "Content-type: text/html \n\n"; print "<html><head><title>Potenzen-Rechner</title></head>\n"; print "<body>"; my $faktor = $zahl; if ($potenz == 0) { print "<h1>Die Lösung ergibt: 1</h1>\n"; exit; } else { if ($potenz >= 0) { for (my $i = 1;$i <= $potenz - 1;$i = $i + 1) { $zahl = $zahl * $faktor; } } else { $zahl = 1/$zahl; $faktor = 1/$faktor; for (my $j = -1;$j >= $potenz + 1;$j = $j - 1){ $zahl = $zahl * $faktor; } } } print "<h1>Die Lösung ergibt: $zahl</h1>\n"; print "</body></html>\n";
1 2 3 4 5 6 7 8 9 10
$daten = <>; @daten = split("",$daten); splice(@daten,3,5); shift@daten; splice(@daten,1,1); @zahl = @daten; pop @zahl; $zahl = join("",@zahl); @potenz = splice(@daten,1,1); $potenz = join("",@potenz);
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
#!/usr/bin/perl -w # bitte immer "strict" und "warnings" nutzen use strict; use warnings; # Programm ist ein CGI use CGI; # Fehler an den Browser use CGI::Carp qw(fatalsToBrowser); # CGI initialisieren my $cgi=CGI->new(); # Header senden WICHTIG! print $cgi->header(); # alle werte holen my $zahl=$cgi->param('zahl') || 0; my $potenz=$cgi->param('potenz') || 0; # HTML einleiten print "<html><body>"; # sind alles Zahlen? # testen mit einem regulären Ausdruck my $regexp=qr(^[+-]?\d+$); if($zahl=~$regexp && $potenz=~$regexp) { my $faktor=$zahl; if ($potenz == 0) { $zahl=1; } elsif ($potenz > 0) { for (my $i = 1;$i <= $potenz - 1;$i = $i + 1) { $zahl = $zahl * $faktor; } } else { $zahl = 1/$zahl; $faktor = 1/$faktor; for (my $j = -1;$j >= $potenz + 1;$j = $j - 1){ $zahl = $zahl * $faktor; } } print "<h1>Die Lösung ergibt: $zahl</h1>\n"; } else { print "<h1>Zahl, Faktor und Potenz müssen Zahlen sein!</h1>\n"; } print "</body></html>\n";
http://deine.url.sonstwo/cgi-bin/das_script.cgi?zahl=10&potenz=10
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
#!/usr/bin/perl -w # bitte immer "strict" und "warnings" nutzen use strict; use warnings; # Programm ist ein CGI use CGI; # Fehler an den Browser use CGI::Carp qw(fatalsToBrowser); # CGI initialisieren my $cgi=CGI->new(); # Header senden WICHTIG! print $cgi->header(); # alle werte holen my $zahl=$cgi->param('zahl') || 0; my $potenz=$cgi->param('potenz') || 0; # HTML einleiten print "<html><body>"; # sind alles Zahlen? # testen mit einem regulären Ausdruck my $regexp=qr(^[+-]?\d+$); if($zahl=~$regexp && $potenz=~$regexp) { $zahl=$zahl**$potenz; print "<h1>Die Lösung ergibt: $zahl</h1>\n"; } else { print "<h1>Zahl und Potenz müssen Zahlen sein!</h1>\n"; } print "</body></html>\n";
1
2
3
4
5
6
7
8
9
10
11
12
13
14
<html>
<head>
<title>Potenzen-Rechner</title>
</head>
<body bgcolor="blue">
<form action="http://192.168.148.135/cgi-bin/real_potenz.pl" method="post">
<p> Bitte die gewünschte Zahl eingeben: <input type="text" name="zahl" value=""></p>
<p>Und die Potenz:<input type="text" name="potenz"></p>
<p><input type="submit" value="berechnen"></p>
</form>
</body>
</html>
2010-10-19T12:03:15 LinuxerBtw. es gibt kein Tag "formaction" ... nur ein "form"-Tag, das ein "action"-Attribut hat.
1
2
3
4
5
6
7
8
9
10
11
12
<html>
<head>
<title>Potenzen-Rechner</title>
</head>
<body bgcolor="blue">
<form action="/cgi-bin/real_potenz.pl" method="post">
<p> Bitte die gewünschte Zahl eingeben: <input type="text" name="zahl" value=""> </p>
<p> Und die Potenz:<input type="text" name="potenz" value=""> </p>
<p> <input type="submit" value="berechnen"> </p>
</form>
</body>
</html>
1
2
Premature end of script headers: real_potenz.pl, referer:
http://192.168.148.135/test_inputbox.html
Guest Sade JEs hat das "#"-Zeichen in der Shebangzeile nicht kopiert...