Random_Walk has asked for the wisdom of the Perl Monks concerning the following question:
Strangely it does not match strings that look to me like obvious matches, it worked when I used a hash to store the mappings (key was pattern, value was mapped severity) but had to change this as processing order is important
I know I must be missing something obvious but I have gone snow blind from staring at it
The following is a reduced test case showing the problem.
#!/usr/bin/perl -w use strict; ################### Test arrays ######################## my @severity_map = ( "Error:Warning", "Warning:Minor", "Critical:Critical", "Alarm:Critical", "System Shutdown:Fatal", "System Powered Off:Fatal", "Failure:Critical", "Memory Bank Deconfigured:Warning", "Uncorrectable ECC:Fatal" ); my @description_samples = ( "Memory Bank Deconfigured", "Uncorrectable ECC", "Sticky Corrected ECC Error", "System Shutdown" ); ################### The code ######################### foreach my $description (@description_samples) { my $severity; foreach (@severity_map) { /(.*):(.*)/; my $regexp = $1; # uncomment following to see why this drives me mad # print "does $description=~/$regexp/i\n"; next unless $description =~ /$regexp/i; $severity = $2; } unless ($severity) { print "can find no severity mapping for: $description "; print "defaulting to WARNING\n"; $severity = "Warning"; } }
Please lead me on the path to enlightenment
my @severity_map = ( ["Error","Warning"], ["Warning","Minor"], ["Critical","Critical"], ["Alarm","Critical"], . . . foreach (@severity_map) { next unless $description =~ /$_->[0]/i; $severity = $_->[1]; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: obvious matching patterns don't match
by Fletch (Bishop) on Aug 18, 2004 at 15:44 UTC | |
|
Re: obvious matching patterns don't match
by roju (Friar) on Aug 18, 2004 at 15:46 UTC | |
|
Re: obvious matching patterns don't match
by blokhead (Monsignor) on Aug 18, 2004 at 15:53 UTC | |
by Random_Walk (Prior) on Aug 18, 2004 at 16:01 UTC | |
|
Re: obvious matching patterns don't match
by beernuts (Pilgrim) on Aug 18, 2004 at 15:58 UTC | |
|
Re: obvious matching patterns don't match
by Zaxo (Archbishop) on Aug 18, 2004 at 16:35 UTC | |
by Random_Walk (Prior) on Aug 18, 2004 at 17:07 UTC |