I'm trying to parse a form with the post method. I have written a
script(formparser.pl) that parses the info and appends it to a flat file.
It then reads the file and outputs the information into two html tables
followed by a third table that is the form you could use to do it again.
On the unix box I have checked the script via (perl -c formparser.pl) and
the syntax is okay. But when I go to the html page with the form and try to
use it, it says that there is a problem. I'm nearly sure the paths are
correct and permissions have all been set.
Any help would be greatly appreciated. Below is a link to the html form
followed by my script (formparser.pl).
byron
http://cgi.wc.pima.edu/~bwise/form2.html
###############################################################################
#!/usr/bin/perl
print "Content-type:text/html\n\n";
$file='/home/bwise/public_html/weather.data';
read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'});
@pairs = split(/&/,$buffer);
foreach $pair (@pairs) {
($name, $value)=split(/=/,$pair);
$value=~tr/+/ /;
$value=~s/%([a-fA-F0-9][a-fA-F0-9])/pack("C",hex($1))/eg;
$value=~s/\n/ /g;
$value=~s/\r//g;
$value=~s/\cM//g;
$form{$name}=$value;
}
open(DATA, ">>formparser.data") or die ("Cannot open formparser.data: $!");
flock(DATA,2);
while ( ($mykey,$myvalue) = each(%form) ) {
print DATA "$myvalue:";
}
close (DATA);
print <<Begin_HTML;
<html><head></head><body>
<table><tr><td bgcolor="#cccccc">DATA ENTRIES</td></tr>
<tr><td><center>DATE</center></td><td><center>TIME</center></td><td><center>TEMP</center></td><td><center>TYPE</center></td></tr>
Begin_HTML
$tottemp=0;
$avgtemp=0;
open(DATA, "$file") or die ("Cannot open $file: $!");
while (<DATA>) {
chomp;
($month,$day,$year,$time,$when,$temp,$type)=split (/:/);
print "<tr><td bgcolor='#ffffff'>$month/$day/$year</td><td>$time
$when</td><td>$temp</td><td>$type</td></tr>","\n";
if ($type eq "clear") {
push(@clear, $type);
}
if ($type eq "tornado") {
push(@tornado, $type);
}
if ($type eq "cloudy") {
push(@cloudy, $type);
}
if ($type eq "rain") {
push(@rain, $type);
}
if ($type eq "hail") {
push(@hail, $type);
}
if ($type eq "sleet") {
push(@sleet, $type);
}
if ($type eq "snow") {
push(@snow, $type);
}
if ($type eq "fog") {
push(@fog, $type);
}
if ($type eq "oobleck") {
push(@oobleck, $type);
}
$a=@temp;
$tottemp = $tottemp + $temp;
$avgtemp = $tottemp/$a;
}
$cl=@clear; #####THESE 9 LINES GET THE LENGTH OF THE ARRAYS SO I
$to=@tornado; #####CAN USE THEM FOR THE NUMBER OF OCCURENCES BELOW
$clo=@cloudy;
$ra=@rain;
$ha=@hail;
$sl=@sleet;
$sn=@snow;
$fo=@fog;
$oo=@oobleck;
print <<Begin_HTML;
####################THIS IS A TABLE THAT LISTS THE OCCURENCES OF EACH TYPE
<TABLE border=0 cellpadding=0 cellspacing=5 bgcolor="#cccccc" width="400px">
<tr><td>
<table border=0 cellpadding=3 cellspacing=1 width="400px">
<tr>
<td bgcolor="#cccccc"><center>ORGANIZED DATA</center></td>
</tr>
<tr>
<td>Average Temperature is: $avgtemp</td>
</tr>
<tr>
<td bgcolor="#ffffff">Clear: $cl</td>
</tr>
<tr>
<td bgcolor="#ffffff">Tornado: $to</td>
</tr>
<tr>
<td bgcolor="#ffffff">Cloudy: $clo</td>
</tr>
<tr>
<td bgcolor="#ffffff">Rain: $ra</td>
</tr>
<tr>
<td bgcolor="#ffffff">Hail: $ha</td>
</tr>
<tr>
<td bgcolor="#ffffff">Sleet: $sl</td>
</tr>
<tr>
<td bgcolor="#ffffff">Snow: $sn</td>
</tr>
<tr>
<td bgcolor="#ffffff">Fog: $fo</td>
</tr>
<tr>
<td bgcolor="#ffffff">Oobleck: $oo</td>
</tr>
</table>
</td>
</tr>
</table>
#######THIS IS THE FORM AGAIN INCASE YOU WANT TO RUN IT AGAIN
<form ACTION="/cgi-bin/formparser.pl" METHOD="POST">
<TABLE border=0 cellpadding=0 cellspacing=5 bgcolor="#cccccc" width="400px">
<tr><td>
<table border=0 cellpadding=3 cellspacing=1 width="400px">
<tr>
<td bgcolor="#cccccc"><center><b>Current Weather</b></center></td>
</tr>
<tr>
<td bgcolor="#ffffff">Below is a form intended for your use.
Please fill out all fields with the appropriate data.
Upon completion, use the submit button. This will allow you to see a
collection of data from other users.</td>
</tr>
<tr>
<td bgcolor="#ffffff"><li>Please enter the month and day as two digit
numbers, and the year as four: <br><center>
Month <INPUT TYPE="text" NAME="month" SIZE="7">
Day <INPUT TYPE="text" NAME="day" SIZE="7">
Year <INPUT TYPE="text" NAME="year" SIZE="7"></center><br><br>
<li>Please enter the hour (12 hour time):<br><center><INPUT TYPE="text"
NAME="time" SIZE="7">
<INPUT TYPE="radio" NAME="when" VALUE="am"> AM
<INPUT TYPE="radio" NAME="when" VALUE="pm"> PM</center><br><br>
<li>Please enter the temperature in Fahrenheit: <INPUT TYPE="text"
NAME="temp" SIZE="7"><br><br>
<li>Enter the type of weather:<br>
<INPUT TYPE="radio" NAME="type" VALUE="clear">Clear<br>
<INPUT TYPE="radio" NAME="type" VALUE="tornado">Tornadoes<br>
<INPUT TYPE="radio" NAME="type" VALUE="cloudy">Cloudy<br>
<INPUT TYPE="radio" NAME="type" VALUE="rain">Rain<br>
<INPUT TYPE="radio" NAME="type" VALUE="hail">Hail<br>
<INPUT TYPE="radio" NAME="type" VALUE="sleet">Sleet<br>
<INPUT TYPE="radio" NAME="type" VALUE="snow">Snow<br>
<INPUT TYPE="radio" NAME="type" VALUE="fog">Fog<br>
<INPUT TYPE="radio" NAME="type" VALUE="oobleck">Oobleck<br>
</tr>
</td>
<tr>
<td bgcolor="#ffffff"><center><INPUT TYPE="submit"
VALUE="Submit">
<INPUT TYPE="reset" VALUE="Reset"></center></td>
</tr>
</table>
</td></tr>
</table>
</body>
</html>
Begin_HTML
exit(0);
##############################################################################
Fear is the path to the dark side. Fear leads to anger, anger leads to
hate, hate leads to suffering.
-=[Yoda]=-
_______________________________________________________
Get 100% FREE Internet Access powered by Excite
Visit http://freelane.excite.com/freeisp
---
You are currently subscribed to perl-win32-users as: [archive@jab.org]
To unsubscribe, forward this message to
[EMAIL PROTECTED]
For non-automated Mailing List support, send email to
[EMAIL PROTECTED]