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

Re^2: Counting keys in a referenced hash

by Locutus (Beadle)
on Dec 03, 2006 at 16:11 UTC ( #587523=note: print w/replies, xml ) Need Help??


in reply to Re: Counting keys in a referenced hash
in thread Counting keys in a referenced hash

Dear Anonymus Monk,

$test doesn't have a value of 6 because unlike an array variable a list literal doesn't evaluate to the number of elements if used in scalar context but to its last element. Try

#!/usr/bin/perl use strict; use warnings; my $scalar = qw/one two three/; my @array = qw/one two three/; print '$scalar is ', $scalar, "\n"; # prints + 'three' print '@array in scalar context is ', scalar @array, "\n"; # prints + 3

for example. Perl supposes you know the length of a literally coded (i.e. hard-coded) list anyway and tries to offer you something more useful when it discovers a "Useless use of a constant in void context"...

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (5)
As of 2020-12-03 17:12 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you use taint mode?





    Results (57 votes). Check out past polls.

    Notices?