Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Re: Pushing an hash into an array

by NetWallah (Abbot)
on May 14, 2013 at 03:28 UTC ( #1033392=note: print w/replies, xml ) Need Help??

in reply to Pushing an hash into an array

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

Replies are listed 'Best First'.
Re^2: Pushing an hash into an array
by sami.strat (Initiate) on May 14, 2013 at 20:08 UTC
    Thanks much. Your recommendations were actually very helpful.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1033392]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (5)
As of 2017-02-28 02:42 GMT
Find Nodes?
    Voting Booth?
    Before electricity was invented, what was the Electric Eel called?

    Results (395 votes). Check out past polls.