would anyone like to fix up this script for me so that it will sort through the SERVER.RND and return the results, I am entirely in newbie land, sorry.
#!/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;
}
}
-----------------------------
This is a random file,
with the extension .RND, and named SERVER.RND.
Each record is exactly 100 bytes long,
makes it easier to calculate.
The fields are as follows:
01-06 JOB NUMBER
07-16 CUSTOMER NAME
17-26 TELEPHONE NUMBER
27-36 AGENCY REFERENCE
37-100 STATUS DESCRIPTION (60 BYTES + 4 BYTES SPACES)
CUSTOMERS
Customer enters Job Number and Telephone Number.
If both match, return the
record showing the Job Number and Status Description.
AGENCIES
Agency enters the Agency Reference.
Return all records that match that
agency, showing Job Number and Status Description.
2002-07-16 Edit by Corion - added CODE tags