Hello wondering if someone could help me out. I have the following script that I am using to search for about 100 records listed in a file against a bunch of log files. The problem is that I think it's searching each line for all 100 records. Not sure what I am doing wrong here hopefully someone can point me in the write direction. Once again here is what I am trying to do. I have a directory full of log files and I want to search through all of those files for matching entries from another file that contains key words. Thanks and please let me know if you have any questions. Thanks again for the help!!
#!/usr/bin/perl use strict; use warnings; use File::Find; my $DIR = "/tmp/logs/"; find(\&queries, $DIR); sub queries() { if ( -f and /^ftr001/ ) { print "----------------------------------------------\n"; print "Searching File:", $_, "\n"; print "----------------------------------------------\n"; open(UNZIP, "gunzip -dc < $_ |") or die "gunzip: $!"; open(RECORDS, "/tmp/logs/records.txt") or die "Could not open +records file: $!"; my @REC=<RECORDS>; chomp @REC; while ( <UNZIP> ) { my $EACH_LINE = $_; foreach my $REC_QUERY (@REC) { print "Searching for current record: $REC_QUERY\n"; if ( $EACH_LINE =~ /\($REC_QUERY\)/ ) { print "Querying for record: $REC_QUERY\n"; print "$EACH_LINE\n"; } } } } } close(UNZIP); close(RECORDS);

In reply to Not sure what I am doing wrong by learningperl01

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.