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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.