!/usr/bin/perl5 &parse_form; # Parse the form $first = $FORM{'first'}; # First number in range $last = $FORM{'last'}; # Last number in range $condition = $FORM{'condition'}; # Condition of each item $maxprice = $FORM{'maxprice'}; # Maximum price customer wants to pay $fields = 4; # Number of fields in each record $filename = "pricelist.txt"; # The database text file $results = 10000; # Maximum number of results to display &open_file("FILE1","",$filename); # Open the database file &mime; &print_top; $counter = 0; if ($first =~ /[^0-9]/) { &error; } if ($last =~ /[^0-9]/) { &error; } while (($line = &read_file("FILE1")) && ($counter < $results)) { # split the fields at the | character @tabledata = split(/\s*\|\s*/,$line ,$fields); &check_record; if ($found == 1) { $counter++; &print_record; } } close(FILE1); if ($counter == 0) { print "
Sorry, No Matches were found.\n"; } &footer; ######################################################################### # # # Subroutines # # # ######################################################################### # Check the record sub check_record { $item_number = $tabledata[0]; $scottnum = $tabledata[1]; $description = $tabledata[2]; $descriptionurl = $tabledata[2]; $price = $tabledata[3]; $keywords = $tabledata[4]; $descriptionurl =~ s/\s/\+/g; $sfound = 0; $found = 0; $notfound = 1; if (($item_number >=$first) && ($item_number <= $last)) { if ($description =~ /$condition/i) { $sfound = 1; } elsif ($condition =~ /all/i) { $sfound = 1; } } else { $notfound = 0; } if ($sfound == 1 && $notfound == 1) { $found = 1; } } # Parse the Form sub parse_form { read(STDIN, $buffer, $ENV{'CONTENT_LENGTH'}); if (length($buffer) < 5) { $buffer = $ENV{QUERY_STRING}; } @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; $FORM{$name} = $value; } } # Open the File sub open_file { local ($filevar, $filemode, $filename) = @_; open ($filevar,$filemode . $filename) || die ("Can't open $filename"); } # Read and/or Write to the File sub read_file { local ($filevar) = @_; <$filevar>; }