For some reason Perl is giving me and unitialized variable error when attempting to take a value out of a hash. Is there any other way of getting the data out of the hash? That same code worked before(gathering port data from a switch) so I'm wondering why it isn't working this time.

The exact output for one xml element is as follows:

Pairname is: RP261

value is HASH(0x10b0060)

Use of uninitialized value in concatenation (.) or string at time_script.pl line 56.

StatA is

#!/usr/bin/perl -w #Status Legend : 1=psNotInstalled,2=psAvailable,3=psBlocked,4=psUnavai +lable, #5=psLinkFailure,6=psLinkFailLOL,7=psIntDiags, 8=psExtLoop,9=psPortFai +l, #10=psSR,11=psLR,12=psInaccessible,13=psInactive ### This script developed by Bill Ruehl, July 2007 ### Version 1.0 This is version 1 of the time check script use strict; #modules used use XML::Simple; use Net::SNMP; use XML::Parser; use XML::Parser::Expat; our ($data, $xml, $e, $value, $IPAddressA, $OID, $session, $error, $st +atA,$resmsg); #create object # Hard Code OID for port status info $OID ="1.3.6.1.4.1.289.2.1.1.2.1.11" ; #Hard Code OID for metrics info #instantiate a parser $xml = new XML::Simple; open LOG, ">>/home/pbkhk/test/log.txt"; # read the XML file $data = $xml->XMLin("/home/pbkhk/test/timetest.xml"); print LOG "This iteration run at: " . localtime() . "\n" ; foreach $e (@{$data->{PairedDevices}}) #Do actions that require use of XML data in this loop possibly #call SNMP data gathering and reporting { print "Pairname is: " . $e->{PairName} . "\n "; print LOG "Pairname is: ". $e->{PairName} . "\n "; $IPAddressA = $e->{DeviceA}->{IPAddress} ; #print "IpAddressA is " . $IPAddressA . "\n"; #print "IpAddressB is " . $IPAddressB . "\n"; if ($e->{ExclusionIndicator} ne "y") #Check to see if host sh +ould be ignored { #print "SNMP test for DeviceA \n"; ($session,$error) = Net::SNMP->session(Hostname => $IPAddr +essA, Community => "public"); } $value = $session->get_request($OID); print LOG "request error " . $session->error unless (defin +ed $value); $session->close; $statA = $value->{$OID}; print "value is $value \n" ; print "StatA is $statA \n"; #print "Date and Time for : $e->{PairName} was $statA \n" +; #print LOG "Date and Time for : $e->{PairName} was $statA \n +"; } close LOG;
Thanks,

-Bill

In reply to Trouble getting data out of a hash by wruehl

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.