Really stuck this time. I have a flat text file database ( reff.data ). The left side will always be different numbers while the right side may be repetitive. The simple part is I inject to the script a number From the left side and ask for the corresponding number on the right side. I inject the number as $line3 submitted from a form.
$data_file="reff.data"; open(DAT, $data_file) || die("Could not open file!"); @raw_data=<DAT>; @results = grep( /^$line[3]/, @raw_data); foreach( @results ) { $record = $_; # strip the beginning key $record =~ s/^\d+//; print "$record"; } close(I);
Great this returns $record which will print out the number corresponding on the right. Now the difficult part. I now need to search the left side for that number and be given again the corresponding number on the right. I have tried the same search for the variable $record thus.
$data_file="reff.data"; open(DAT, $data_file) || die("Could not open file!"); @raw_data=<DAT>; @results = grep( /^$record/, @raw_data); foreach( @results ) { $record2 = $_; # strip the beginning key $record2 =~ s/^\d+//; print "$record2"; } close(I);
But that printed out the whole database I can inject a number from the left and be given the Corresponding right. But then I need the script to go on and find that corresponding number in the left, and give again the corresponding right and so on and so on. I am not a module man but I have tried many things Some with surprising results However after being bogged down with this problem For about three months now, I really need to get past this and Soldier on . God bless Ye All…Nasa.

edited: Sat Feb 15 20:53:30 2003 by jeffa - title change (was: Bewildered.)


In reply to Problem with (recursively?) searching flat file database by nasa

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.