TStanley has asked for the wisdom of the Perl Monks concerning the following question:
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:#!/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;
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?$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' },
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Loading a HoH
by fruiture (Curate) on Oct 11, 2002 at 16:26 UTC | |
|
Re: Loading a HoH
by Enlil (Parson) on Oct 11, 2002 at 15:46 UTC | |
by tadman (Prior) on Oct 11, 2002 at 16:19 UTC | |
|
Re: Loading a HoH
by TStanley (Canon) on Oct 19, 2002 at 17:33 UTC |