in reply to Looping through a file

What have you done to track the path of code executed during your test?

What's $ordnum supposed to be?

If the contents of the Parts file are text, why are you doing a numeric equivalence test?

Where's use strict; use warnings;?

I know my logic is a little off, but can't seem to iron it out.
Write pseudo-code. Say your answer in English to your room-mate. How would you resolve the problem manually?

Replies are listed 'Best First'.
Re^2: Looping through a file
by baixiaohu (Initiate) on Apr 15, 2008 at 21:01 UTC
    I have a print request from a database query I just ran. I'd like to check to see if I've already printed this request. Previo +us requests are in a .txt file. Open the text file and read in all the prior print jobs. If the print request from the database query is in the text file, skip + it. If the print request from the database query is not in the text file, +create a new .dat file for printing.
      First, you want to load the contents of <PARTS> into a hash, not an array.

      Then, you test for the existence of the database query in the hash. If it's not already defined, create the new file.

      How would you implement these two pieces?

        I've created a hash like this:
        open(PARTS, $partlist) || die "Can't open file: $!"; chomp(@PARTS = <PARTS>); %hash_table = (@PARTS);
        To evaluate it so I do something like this?
        foreach (keys %hash_table) { if ($_ eq $ordnum) { #do something } else { #do something else } }