c has asked for the wisdom of the Perl Monks concerning the following question:
I have the following subroutine:
sub get_latest_avg { my $host = shift; my $rrd = shift; my $type = shift; + my $snmp = Net::SNMP->session( -hostname => $host, -version => '1', -community => $nodes{$host}->{community}, ); + my $num = $snmp->get_request( -varbindlist => [$rrd{$rrd}{$type}] +) + ; + my $avg = $num->{$rrd{$rrd}{$type}}; + $snmp->close; + return $avg; + }
I call this subroutine from within another for loop:
for my $host(keys %nodes) { for my $rrd(keys %rrd) { my $avg = &get_latest_avg($host,$rrd,'free'); print $avg. "\n"; } }
I've confirmed each of the variables are assigned correctly through various print statements in key places. What is unusual is that no matter how i order the keys of %rrd, only the first pass returns a valid value. The remaining passes over the other keys return '-1' as the value.
Your input is very appreciated. -c
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Return from a subroutine generates a negative value
by TomDLux (Vicar) on Aug 07, 2003 at 23:01 UTC | |
by c (Hermit) on Aug 07, 2003 at 23:35 UTC | |
Re: Return from a subroutine generates a negative value
by LazerRed (Pilgrim) on Aug 08, 2003 at 00:28 UTC | |
Re: Return from a subroutine generates a negative value
by eric256 (Parson) on Aug 07, 2003 at 23:26 UTC | |
by TomDLux (Vicar) on Aug 08, 2003 at 00:18 UTC | |
by bobn (Chaplain) on Aug 08, 2003 at 02:14 UTC |
Back to
Seekers of Perl Wisdom