in reply to obvious matching patterns don't match
Another problem is that your demo loop keeps overwriting $severity without giving you anything about successful matches. The commented print, if triggered, showed that you had a match.
I don't understand your need for a regex at all. You say that you get multiple matches with them, and so have to do without the tidy hash. I don't understand that.A hash key can only be found if it the exact string you try.
I notice that you are using case-insensitive matching. Was that the real reason, that some clients don't honor case of the error names? If so, you can change case in the descriptions before the hash lookup.
Other than the case insensitivity, you're really testing for equality of strings. The regexen and the problems they cause are neither of them necessary.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", 'DANGEROUS DILITHIUM STATE', "Sticky Corrected ECC Error", "SYSTEM SHUTDOWN" ); for (@desctiption_samples) { my $severity = exists $severity_map{ lc($_) }? $severity_map{ lc($_) } : 'Warning'; print exists $severity_map{ lc($_) } ? "Severity of $_ is $severity_map{ lc($_) }\n" : "No map found for $_: '$severity' level assigned.\n"; }
After Compline,
Zaxo
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: obvious matching patterns don't match
by Random_Walk (Prior) on Aug 18, 2004 at 17:07 UTC |