in reply to Search a file with ids from another file

Hi,

foreach my $prime_id ( @id_hits ) { $line = shift @log until $line =~ /$prime_id/;

you're shifting elements off @log on the first run.
@log gets shortened this way.

Think of the first $prime_id not found in the logfile at all this will result in @log being empty on the second run of the foreach loop. Did you consider this?

I'm not sure about the structure of $prime_id's in relation to the logfile's content but it may result in some unpredictable results.

Hope this helps.
RL

Replies are listed 'Best First'.
Re^2: Search a file with ids from another file
by sigzero (Novice) on May 07, 2007 at 18:51 UTC

    I had not...bf on my part.

    @id_hits looks like this:

    G81432 G81765 H43121

    And more like that...

    So I want to loop through the log for each one of those, find it and capture the "next" line after it.

      So I want to loop through the log for each one of those, find it and capture the "next" line after it.

      Are the lines which can match the ids in the same order as the ids? To each id does correspond a unique matching line? How many are the ids? (This can make a difference - since you print them, I suppose they're not too many.) Are they all in this form? (i.e. a capital letter followed by five numbers.) Can the "next" line also match one id, or is this impossible a priori?

        There are probably 50 or 60 ids.

        The next line cannot match the one id. I should have posted a copy of that as well but basically 1 id will create 2 lines in the logfile and it is that second line I am trying to get at.