http://www.perlmonks.org?node_id=282048

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