in reply to uninitialized value with Tie::IxHash and Net::SNMP

Near as I can tell, is choking on $snmp{response}->{$mib{key}}, What might I be doing wrong here?
I'm guessing that should be $snmp{response}->{$mib{$key}}.

Replies are listed 'Best First'.
Re:(2) uninit value, Tie::IxHash, Net::SNMP (thanks, working snippet)
by ybiC (Prior) on May 18, 2001 at 20:50 UTC
    Thanks and ++ to danger and chipmunk for pointing out my blind spot: second $ in $mib{$key}   Working code snippet below (tweaked a bit more).
        cheers,
        Don
        striving toward Perl Adept
        (it's pronounced "why-bick")
    #! /usr/bin/perl -w # netsnmpTinker.pl # ybiC 2001-05-18 13:30 # derived from Net::SNMP example1.pl # online MIB browser at http://www.ibr.cs.tu-bs.de/cgi-bin/sbrowser.cg +i use strict; use Net::SNMP; use Tie::IxHash; my %snmp; ($snmp{session}, $snmp{error}) = Net::SNMP->session( -hostname => shift || 'localhost', -community => shift || 'public', -port => shift || 161, ); tie my %mib, "Tie::IxHash"; %mib = ( # sysDescr => '1.3.6.1.2.1.1.1.0', sysUpTime => '1.3.6.1.2.1.1.3.0', sysContact => '1.3.6.1.2.1.1.4.0', sysName => '1.3.6.1.2.1.1.5.0', sysLocation => '1.3.6.1.2.1.1.6.0', ifNumber => '1.3.6.1.2.1.2.1.0', cdpAddress => '1.3.6.1.4.1.9.9.23.1.2.1.1.4', cdpDeviceID => '1.3.6.1.4.1.9.9.23.1.2.1.1.6', cdpHWtype => '1.3.6.1.4.1.9.9.23.1.2.1.1.8', ); unless (defined($snmp{session})) { printf(" Error: %s.\n", $snmp{error}); exit 1; } printf("\n Host = %s\n", $snmp{session} ->hostname()); for(keys %mib) { if (defined($snmp{response} = $snmp{session}->get_request($mib{$_}) +)) { printf(" $_ = %s\n", $snmp{response}->{$mib{$_}}); } else { print " $_ = not responding\n"} } $snmp{session}->close(); print "\n"; exit 0;