in reply to Re: Search Script
in thread Search Script

Roy thank you for replying. The below script is what I think you were saying.
print"\n"; print "Please enter file name and path:"; chomp($filename = <STDIN>); print "File Name: $filename"; print "\n"; open DAFILE, "$filename"; open (HintsFile, "Hints.txt") or die "Can't find file\n"; #$input = <DAFILE>; $hints = <HintsFile>; open(testfile,"Hints.txt"); $i=0; @daarray = (); while(<testfile>){ $daarray[$i] = $_; $i++; } close(testfile); for($j=0; $j<$i; $j++) { $hints = $daarray[$j]; ($first,$last) = split(/\ == /,$hints); if($first =~ m/$input/i) {print "Found: $last"; print "\n"; } } print "Search Complete\n"; close DAFILE; close HintsFile;
Thank you very much for the advice! I'm still having some issues with the search, any thoughts? arebc

Replies are listed 'Best First'.
Re^3: Search Script
by Roy Johnson (Monsignor) on May 04, 2005 at 17:48 UTC
    You've got a lot of clutter in there. You are opening Hints.txt in two places, for example. You need to clearly understand what you want the computer to do, and in what order. Then code that. It might help for you to write out the steps in English (or other language of your choice) in comments first. Then under each step, write the code to perform that step. You might find that the code almost writes itself, then.

    You have a lot of pieces that are more or less what you will want to use, but you haven't got them put together right. In particular, it doesn't look like you're reading DAFILE any more. You need to have a read-loop for that, surrounding the for-$j loop, so that the j loop is executed for every line read from DAFILE.


    Caution: Contents may have been coded under pressure.