It has 10,100 items. Currently, there are multiple listings with the same catalog number but different descriptions and prices. I want to be able to give the program two arguements: a first number and a last number and have it display everything in between. Right now I'm doing that by adding an extra field that is basically a line number in front of the catalog number and looping through until it finds the first number, then it prints everything until it reaches the last number. However, I'd like to use the catalog numbers as the numbers I use for the first and last arguements.
To see an example of what I'm doing, click here. Here's my code:
Any suggestions on how I could make it so I could pass it the two Catalog numbers instead of the control numbers?!/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 p +ay $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 "<TR><TD colspan=4><BR><B> Sorry, No Matches were found.</B> +</TD></TR>\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>; }
In reply to More Flat-File Database Questions by Stamp_Guy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |