1. Always use warnings; use strict; !
  2. This is not such a big issue but it's considered better and safer to use the 3-arg open and lexical filehandles, e.g. open my $fh, '<', $infile or die "Could not open $infile: $!";
  3. Problem: This: $/ = "#>\n"; sets the input record separator globally from that point forward, including the point in the current code where you're reading the configuration file. That means that currently, <CONFIG> will read the entire file at once. You should at least use local $/ = "#>\n"; in a new block and follow the next tip:
  4. Parsing the whole configuration file for every line of input is inefficient; instead read the configuration file once at the beginning of the script and store its values in a data structure such as an array of arrays for later use. This also helps avoid the previous problem of the input record separator.
  5. The configuration file format is unclear and the loop for $checkItem (@configLineItems) doesn't make much sense to me. This is probably also because your sample configuration file "patterns" don't match any of the messages from the sample log file. I'm going to wager a guess that the format of the configuration lines is: "Message::Pattern::Pattern" etc. In that case I would suggest that you shift the first item off the array before the aforementioned loop, as in my $message = shift @configLineItems; and then use $message instead of $configLineItems[0].
  6. Instead of "$Line[6]" =~ $checkItem, this is better: $Line[6] =~ /\Q$checkItem/ (however if $checkItem contains actual regular expressions, drop the \Q) - see perlre for more information. The anchors ^ and $ as well as the modifier /i may be of interest to you.

Please try these suggestions, and if you have further questions, please provide the updated code and better sample input (both logfile and configuration file), as well as the desired output.


In reply to Re: Regex perl grep usage string match comparison by Anonymous Monk
in thread Regex perl grep usage string match comparison by justinkala

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.