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.

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"; }
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.

After Compline,
Zaxo


In reply to Re: obvious matching patterns don't match by Zaxo
in thread obvious matching patterns don't match by Random_Walk

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.