Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: Return from a subroutine generates a negative value

by TomDLux (Vicar)
on Aug 07, 2003 at 23:01 UTC ( [id://282054]=note: print w/replies, xml ) Need Help??


in reply to Return from a subroutine generates a negative value

You cannot order hash keys, by definition, their order is arbitrary.

What I understand by first pass means that for one key $host from %nodes, $rrd takes on the values from %rrd in thje way you expect, but it does not for the other keys in %nodes. I doubt that is what you mean ... or if it is, you are not showing the relevant coded, since %rrd is not modified in the code you present.

How about putting a print statement in the inner loop, to see what is happening?

for my $host(keys %nodes) { for my $rrd(keys %rrd) { printf "host: %s\trrd: %s\n", $host, $rrd; # my $avg = &get_latest_avg($host,$rrd,'free'); # print $avg. "\n"; } }

--
TTTATCGGTCGTTATATAGATGTTTGCA

Replies are listed 'Best First'.
Re: Re: Return from a subroutine generates a negative value
by c (Hermit) on Aug 07, 2003 at 23:35 UTC
    I understand what you're saying about the random order of hash keys. However, in my situation, its always the first one that succeeds, regardless of which keys its using. The rest always return -1 as the result of the return. I've tried adding hosts to the %nodes hash and always, the first host works, and the rest fail, no matter which host is selected in the first iteration of the for loop. Hosts that failed in a previous run, run properly if they are the first in line.

    To plug in some values for the hashes I use (both are declared outside of the for loops), I'm adding this:

    my %nodes = ( 'host1' => { 'hardware' => 'servers', 'community' => "$serverCommunity", }, 'host2' => { 'hardware' => 'servers', 'community' => "$serverCommunity", }, ); my %rrd = ( 'real_trend' => { 'free' => $memAvailReal, 'desc' => 'Physical Memory', }, 'swap_trend' => { 'free' => $memAvailSwap, 'desc' => 'Swap Memory', }, );

    I just don't think these values matter that much since their order seems unimportant.

    I somehow think the issue may be in the snmp session somehow however I have no clue as to why.

    Thanks very much for your time on this -c

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://282054]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (5)
As of 2024-04-25 16:19 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found