I have one file where I use the substr to get out all the id's and push them into an array.
I then open the log file and find the line that the id shows up on, but I actually want the next line to be the message that goes into the OUTFILE.
I think the problem is with the foreach loop as I am getting an error.
Error: Use of uninitialized value in pattern match (m//) at ./amp_parse.pl line 39,
use strict; use warnings; my $IDFILE = 'H_E'; my $AMPFILE = 'a.log'; my $OUTFILE = 'report.lst'; my @id_hits; # loop through the id file to get the prime id from each line and # push it onto the @hits array # open my $IFILE, '<', $IDFILE or die "Could not open $IDFILE: $!"; my @id_hits=map substr($_, 0, 6), <$IFILE>; #print "@id_hits"; # loop through the amp.log find the line matches for the hits in # this @id_hits array. # open my $AFILE, '<', $AMPFILE or die "Could not open $AMPFILE: $!"; my ( $line, $next_line ); my @log = <$AFILE>; while ( @log ) { foreach my $prime_id ( @id_hits ) { $line = shift @log until $line =~ /$prime_id/; undef $line; $next_line = shift @log until $next_line =~ /^AMP-commit/; my $amp_msg = $next_line; undef $next_line; open my $OFILE, '>', $OUTFILE or die "Cannot create report fil +e: $!"; print $OFILE "$prime_id:\t$amp_msg\n" or die "Cannot print to +file: $!"; close $OFILE; } }
Any help and suggestions?
Robert
In reply to Search a file with ids from another file by sigzero
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |