kp2a has asked for the wisdom of the Perl Monks concerning the following question:
unexpected result
hash reference passed to subroutine
filled in subroutine shown by debug print
found empty by calling routine
subroutine
filled in subroutine shown by debug print
found empty by calling routine
subroutine
calling routine#! /usr/bin/perl -w use strict; use api::Mtik; use api::printhash; sub getsnmp { my $hashref = shift or die; my $debug = shift || 0; print LOG "getsnmp: entry debug $debug\n" if $debug; %$hashref = (); my @command; push @command,'/snmp/print'; push @command,'.id'; my($retval,@results) = &Mtik::talk(\@command); if ($retval != 1) { return $results[0]{'message'}; } $hashref = $results[0]; if($debug) { printhash($hashref,"getsnmp: return value"); } return ""; } 1;
debug print#! /usr/bin/perl -w use strict; use DBI; use bbvi::iptools; use api::Mtik; use api::printhash; use api::getsnmp; my $ip = $ARGV[0] || '10.105.41.166'; isip($ip) or die; open LOG,">testresult.txt" or die; unless(Mtik::login($ip,'admin','xxxxxxxx')) { die "login failed\n" } my %hash = (); if(my $error = getsnmp(\%hash,1)) { printf LOG qq{%3d: get snmp failed - \"$error\"\n},__LINE__; exit; } printhash(\%hash,"hash returned from getsnmp");
getsnmp: entry debug 1 getsnmp: return value 'contact'=>'' 'enabled'=>'true' 'engine-id'=>'' 'location'=>'' 'trap-community'=>'(unknown)' 'trap-generators'=>'' 'trap-target'=>'0.0.0.0' 'trap-version'=>'1' results hash 'contact'=>'' 'enabled'=>'true' 'engine-id'=>'' 'location'=>'' 'trap-community'=>'(unknown)' 'trap-generators'=>'' 'trap-target'=>'0.0.0.0' 'trap-version'=>'1' hash returned from getsnmp
Back to
Seekers of Perl Wisdom