The following code is provided for your ponderance:
#!/opt/perl5/bin/perl -w use strict; ## Setup and precompile the errorcodes ## my $err1=qr/Disconnected/o; my $err2=qr/sopup\.sh/o; my $err3=qr/switch_sh\.sh/o; my $err4=qr/Node/o; my $err5=qr/^NetBIOS/io; my $err6=qr/Manual/o; my $err7=qr/Beginning/o; my $err8=qr/AUP rejecting duplicate transaction/o; my $err9=qr/LAN/o; my @Messages=("$err1","$err2","$err3","$err4","$err5","$err6","$err7", +"$err8","$err9"); ## Precompile Regular Expressions my $A=qr/(Packet ID)\s+\(hex\)\s+(\w+)\s+(Origin)\s+([\w\s]+)/o; my $B=qr/(Date)\s+\(mm\/dd\/yyyy\)\s+(\d{2}\/\d{2}\/\d{4})\s+(Qualifie +r)\s+(\w+)/o; my $C=qr/(Time)\s+(\d{1,2}:\d{2}:\d{2}\.?\d{2}?)\s+(Terminal ID)\s+(\d ++)/o; my $D=qr/(Device ID)\s+\(hex\)\s+(\w+)\s+(Application ID)\s+(\w+)/o; my $E=qr/(Catalog Code)\s+(\w+)\s+(Function ID)\s+\(hex\)\s+(\w+)/o; my $F=qr/(Status)\s+(-?\d+)\s+(Severity)\s+(\d+)/o; my $G=qr/(.*)/o; my @LineRegexs=("$A","$B","$C","$D","$E","$F"); $/="------------------------------------------------------------------ +------------\n"; my (%hash,$count,$line); $count=1; open(FH,"$path")||die"Can't open $File: $!\n"; while(<FH>){ chomp; my @array=split /\n/; foreach my $line(@array){ chomp; foreach my $regex(@LineRegexs){ if($line=~$regex){ $hash{$count}{$1}=$2; $hash{$count}{$3}=$4; } next; } if($line=~$G){ $hash{$count}{'Error Message'}=$line; $count++; next; }else{ next; } }#END OF FOREACH STATEMENT }## END OF WHILE STATEMENT ## close FH;
The above code is not providing the expected results from the data file that I am opening. A partial file from dumping the hash (using Data::Dumper) will show what I mean:
$VAR1 = { '25710' => { 'Error Message' => 'Status 1 Severity 2', 'Severity' => '2', 'Status' => '1' }, '25711' => { 'Error Message' => 'Process started tmclean.sh' }, '25712' => { 'Error Message' => 'Packet ID (hex) 0xF040 Origin UNIX ', 'Origin' => 'UNIX ', 'Packet ID' => '0xF040' }, '32930' => { 'Error Message' => 'Catalog Code UNIX Function ID (hex) 0x8011', 'Catalog Code' => 'UNIX', 'Function ID' => '0x8011' },
How would I go about looping through the array of regular expressions for each line, and stop once a match is found, then move on to the next line in the file?

TStanley
--------
It is God's job to forgive Osama Bin Laden. It is our job to arrange the meeting -- General Norman Schwartzkopf

In reply to Loading a HoH by TStanley

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.