Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things
 
PerlMonks  

Number of Elements in HoL

by Tuna (Friar)
on Aug 22, 2001 at 17:42 UTC ( [id://106945]=perlquestion: print w/replies, xml ) Need Help??

Tuna has asked for the wisdom of the Perl Monks concerning the following question:

Monks, this is frustrating. Why doesnt the following work? I get an undefined variable returned.
in getClusterHostCount$VAR1 = '/saconfig/current/cluster1'; $VAR2 = [ 'localhost', 'eh050su2' ]; sub getClusterHostCount { print "******************entering getclusterhost count\n"; my $hostcount = ( @{$ClusterHostList{ $clusterID }} ) ; print "count = $hostcount\n"; print "in getClusterHostCount", Dumper (%ClusterHostList); return $hostcount; }

Replies are listed 'Best First'.
Re: Number of Elements in HoL
by perrin (Chancellor) on Aug 22, 2001 at 17:58 UTC
    It looks like you're putting that array ref in list context when you want scalar context. Try this:
    my $hostcount = scalar(@{$ClusterHostList{ $clusterID }});
    Technically, I don't think you need that "scalar()", but it's good documentation of what you're doing.
Re: Number of Elements in HoL
by MZSanford (Curate) on Aug 22, 2001 at 17:51 UTC
    I don't see $clusterID getting set, if that is not just acopy/paste error, i think thats the cause ... i used the folowing for a test :
    $ClusterHostList{'/saconfig/current/cluster1'} = ['localhost','eh050su +2']; &getClusterHostCount('/saconfig/current/cluster1'); sub getClusterHostCount { print "******************entering getclusterhost count\n"; my $clusterID = shift; my $hostcount = scalar @{ $ClusterHostList{$clusterID} } ; print "count = $hostcount\n"; return $hostcount; }
    .. and suvery says ...
    ******************entering getclusterhost count count = 2

    Update : /me being stupid. It was set (thanks Tuna), so my other fix (scalar) was what did it.
    can't sleep clowns will eat me
    -- MZSanford

Log In?
Username:
Password:

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

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

    No recent polls found