On Friday 02 July 2004 15:07, Randy W. Sims wrote:
Wiggins d Anconia wrote:
You can take the list in a scalar context, or force it into a scalar context, such as,
my $num = keys %{ $printers{jobs} };
or the more verbose,
my $num = scalar keys %{ $printers{jobs} };
'values' works in place of 'keys' since it is a 1-to-1 relationship, keys is my preferred.
Don't forget the oft forgot and more efficient
print scalar %hash;
eg.
my %hash = ( A => 1, B => 2, C => 3 ); print scalar %hash; => 3/8
Neither the 3 nor the 8 nor 3 divided by 8 has any relation to the number of keys or number of values in the hash.
D'oh, you're right, of course. I was thinking it "returned number of elements/number of buckets"; it's really "number of used buckets/number of allocated buckets" or false if there are no elements. Shows how much I use the feature (and that I should really check more before posting).
Thanks for the correction, Randy. (who confuses more than clarifies lately)
-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>