jdawes has asked for the wisdom of the Perl Monks concerning the following question:
#!/usr/bin/perl -- &getformdata; print "Content-type: text/html\n\n"; print "<center><h2>Request Data</h2><p>\n"; if ($FORM{todolist} eq '') {print " <form action=$ENV{REQUEST_URI} method=post> <table> <tr><td>Job Number:</td><td><input name=jobnumber size=20></td></tr> <tr><td>Phone Number:</td><td><input name=phonenumber size=20></td></tr> </table> <input type=hidden name=todolist value=search> <input type=submit value=Search></form>\n"; } elsif ($FORM{todolist} eq 'search') { print "searching<p>\n"; &loaddata; sub loaddata { $datafilename = 'webserver.rnd'; open(DATAFILE, $datafilename) or print "Can't open data"; @data = <DATAFILE>; close(DATAFILE); while(<DATAFILE>) { if(length<101) { # 1 more for newline chomp; warn "Record '$_' too short, skipping"; next; } push @jobNumbers, substr $_,0,6; push @customerNames, substr $_,6,10; push @telephoneNumbers, substr $_,16,10; push @agencyReferences, substr $_,26,10; # adjust either start or end if you need to skip spaces push @statusDescriptions, substr $_,36,64; } } { print "searching<p>\n"; &loaddata; $found = 0; foreach $entry (@data) { ($a, $b, $c, $d) = split(/:/, $entry); if ($a eq $FORM{jobnumber}) { if ($b eq $FORM{phonenumber}) { print "$d <br>\n"; $found = 1; } } } if ($found == 0) {print "no matches found<br>\n";} } sub getformdata { 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/<([^>]|\n)*>//g; $FORM{$name} = $value; } }
2002-07-16 Edit by Corion - added CODE tags
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help Fixing Script
by cjf (Parson) on Jul 16, 2002 at 07:23 UTC | |
by jdawes (Novice) on Jul 16, 2002 at 07:27 UTC | |
by jdawes (Novice) on Jul 17, 2002 at 01:19 UTC |