Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

help fix script?

by jdawes (Novice)
on Jul 16, 2002 at 06:59 UTC ( [id://182016]=perlquestion: print w/replies, xml ) Need Help??

jdawes has asked for the wisdom of the Perl Monks concerning the following question:

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

Replies are listed 'Best First'.
Re: Help Fixing Script
by cjf (Parson) on Jul 16, 2002 at 07:23 UTC
      ok, i'll do that :)
        ok, i read that stuff, understood about half of it.
        I guess i should incorporate this diagnositcs things into the script..

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://182016]
Approved by rob_au
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (None)
    As of 2024-04-25 01:33 GMT
    Sections?
    Information?
    Find Nodes?
    Leftovers?
      Voting Booth?

      No recent polls found