Welcome to the Monastery!

$element contains "Battery Failure".

There is no such key in %error_code, so $error_code{$element} returns undef.

The nearest valid key would be "SysBatteryFailure" , so you need to figure out how to get that into $element.

ALso, you need to decide if @ILO_ERRORS has a hashref element, or is a simple array. You are attempting to use it both ways.

After you get $element set correctly, if you want to use @ILO_ERRORS as an array, try:

my @ILO_ERRORS = (); # Empty LIST; not {}, which is a hash ref ... push @ILO_ERRORS, $error_code{$element}; .... if (@ILO_ERRORS) { print "SNMP CRITICAL - @ILO_ERRORS \n"; # Note - array interpolated + INSIDE QUOTES, "\n" added ...
To get $element to work right, you could try:
my ($key) = grep {$error_code{$_} =~/$element/} keys %error_code; # Note - parens around ($key) provide the required list context $key and push @ILO_ERRORS, $error_code{$key};

             "I'm fairly sure if they took porn off the Internet, there'd only be one website left, and it'd be called 'Bring Back the Porn!'"
        -- Dr. Cox, Scrubs


In reply to Re: Pushing an hash into an array by NetWallah
in thread Pushing an hash into an array by sami.strat

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.