sigzero has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Search a file with ids from another file
by blazar (Canon) on May 07, 2007 at 19:14 UTC | |
by sigzero (Novice) on May 07, 2007 at 20:29 UTC | |
|
Re: Search a file with ids from another file
by Not_a_Number (Prior) on May 07, 2007 at 19:57 UTC | |
|
Re: Search a file with ids from another file
by RL (Monk) on May 07, 2007 at 18:07 UTC | |
by sigzero (Novice) on May 07, 2007 at 18:51 UTC | |
by blazar (Canon) on May 07, 2007 at 19:21 UTC | |
by sigzero (Novice) on May 07, 2007 at 20:17 UTC | |
by blazar (Canon) on May 07, 2007 at 20:44 UTC | |
|
Re: Search a file with ids from another file
by Moron (Curate) on May 07, 2007 at 18:24 UTC |