ybiC has asked for the wisdom of the Perl Monks concerning the following question:
#! /usr/bin/perl require 5.6.1; # for Net::SNMP v4 use strict; # avoid D'oh! prob +lems use warnings; # avoid D'oh! prob +lems use Net::SNMP 4 qw(snmp_dispatcher oid_lex_sort); # must be >= versi +on 4 use Tie::IxHash; # insertion-order +retrieval my ($session, $error) = Net::SNMP->session( -hostname => 'catalyst', -community => 'public', ); unless (defined($session)) { print "Error: $error"; exit; } tie my %oid, "Tie::IxHash"; %oid = ( TpFdbAddress => '.1.3.6.1.2.1.17.4.3.1.1', TpFdbPort => '.1.3.6.1.2.1.17.4.3.1.2', bridgePortNum => '.1.3.6.1.2.1.17.1.4.1.1', switchPortNum => '.1.3.6.1.2.1.17.1.4.1.2', ifDescr => '.1.3.6.1.2.1.2.2.1.1', ifName => '.1.3.6.1.2.1.31.1.1.1.1', ); for my $value (keys %oid) { if (defined(my $response = $session -> get_table(-baseoid => $oid{$v +alue}))) { print "\n == hash key == $oid{$value} ==\n"; for my $r(oid_lex_sort(keys(%{$response}))) { print($response -> {$r}, ",\n"); } } else { print "Error: ",($session -> error(), ",\n"); } } $session->close; exit;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Print hash value and key in for keys loop
by danboo (Beadle) on Dec 14, 2001 at 02:25 UTC | |
by ybiC (Prior) on Dec 14, 2001 at 02:48 UTC | |
by danboo (Beadle) on Dec 14, 2001 at 03:39 UTC | |
|
Re: Print hash value and key in for keys loop
by Zaxo (Archbishop) on Dec 14, 2001 at 02:42 UTC |