#!/usr/bin/perl -- &getformdata; print "Content-type: text/html\n\n"; print "

Request Data

\n"; if ($FORM{todolist} eq '') {print "

Job Number:
Phone Number:
\n"; } elsif ($FORM{todolist} eq 'search') { print "searching

\n"; &loaddata; sub loaddata { $datafilename = 'webserver.rnd'; open(DATAFILE, $datafilename) or print "Can't open data"; @data = ; close(DATAFILE); while() { 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

\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
\n"; $found = 1; } } } if ($found == 0) {print "no matches found
\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///g; $value =~ s/<([^>]|\n)*>//g; $FORM{$name} = $value; } }