Ok, I have no access to any SQL server whatsoever, and I'm stuck using flat files. I have a database that is in the following format:
CAT #    DESCRIPTION    PRICE

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:

!/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>; }
Any suggestions on how I could make it so I could pass it the two Catalog numbers instead of the control numbers?

In reply to More Flat-File Database Questions by Stamp_Guy

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.