in reply to obvious matching patterns don't match
If we reach this second line, the match must have succeeded, which would have reset $2 to undef.next unless $description =~ /$regexp/i; $severity = $2;
A simpler way to do this is to use a hash for %severity_map. Heck, you already call it a map, but it's not in a normal form -- you have to unpack/decode it (with split) every time you use it to get to the actual data. That's a sure sign that you should rethink a data structure. With a hash, you can avoid having nested loops, and simply perform one regex match:
my %severity_map = ( "Error" => "Warning", "Critical" => "Critical", "System Shutdown" => "Fatal", "Failure" => "Critical", "Uncorrectable ECC" => "Fatal", "Warning" => "Minor", "Alarm" => "Critical", "System Powered Off" => "Fatal", "Memory Bank Deconfigured" => "Warning" ); my @description_samples = ( "Memory Bank Deconfigured", "Uncorrectable ECC", "Sticky Corrected ECC Error", "System Shutdown" ); my $keywords = join "|" => map quotemeta, keys %severity_map; for (@description_samples) { my $severity = "Warning"; /($keywords)/i ? $severity = $severity_map{$1} : print "Can't find severity mapping for: $_, using default\n" +; print "$_ has severity $severity\n"; }
blokhead
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: obvious matching patterns don't match
by Random_Walk (Prior) on Aug 18, 2004 at 16:01 UTC |