This is one of my first perl apps and I'm having issues pushing a hash into an array.

The code sample is below, I've documented the place where the problem lies. Any help would be greatly appreciated. Thanks in advance.

#!/usr/bin/perl my $RESULT="OK"; use strict; use warnings; my $STATE_OK=0; my $STATE_WARNING=1; my $STATE_CRITICAL=2; my $STATE_UNKNOWN=3; my %error_code = ( SysBatteryFailure => 'System Battery Failure', PowerRedundencyFailure => 'Power Redundency Failure', FltTolPowerSupplyFailed => 'Fault Tolerant Power Suppl +y Failure', ); my $SysBatteryFailure=`echo \"Battery Failure\" | grep Failure`; my $PowerRedundencyFailure=`echo \"Power Redundency Failure\" | grep t +rash`; my $FltTolPowerSupplyFailed=`echo \"Power Supply Failure\" | grep tras +h`; my @STATUS = ($SysBatteryFailure, $PowerRedundencyFailure, $FltTolPowe +rSupplyFailed); my @ILO_ERRORS = (); foreach my $element (@STATUS) { chomp $element; if ($element) { # The element variable is accurate here print "$element\n"; # the following line fails. I want to push the hash # into the array. Any idea why it fails? push (@ILO_ERRORS, $element); } } if (@ILO_ERRORS) { print "SNMP CRITICAL - ", @ILO_ERRORS; exit $STATE_CRITICAL; } else { print "SNMP OK - $STATE_OK"; exit $STATE_OK; }

The result of this code is:

root@yosemite SNMP# ./2

Battery Failure

Use of uninitialized value $ILO_ERRORS1 in print at ./2 line 37.

SNMP CRITICAL - HASH(0x11f1018)

root@yosemite SNMP# vi 2


In reply to 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.