Bug#810156: scalar of hashes not documented
積丹尼 Dan Jacobson
jidanni at jidanni.org
Thu Jan 7 23:46:34 UTC 2016
>>>>> "NT" == Niko Tyni <ntyni at debian.org> writes:
>> perldoc -f scalar makes absolutely no mention of what we see (/) here:
>> $ perl -wle '$h{a}=0; print scalar %h;'
>> 1/8
NT> It doesn't explain what happens when you evaluate an array in scalar
NT> context either, and I don't think it should.
Well at least it has an example.
@counts = ( scalar @a, scalar @b, scalar @c );
NT> However, perldata.pod has this paragraph under "Scalar values":
NT> If you evaluate a hash in scalar context, it returns false if
NT> the hash is empty. If there are any key/value pairs, it returns
NT> true; more precisely, the value returned is a string consisting
NT> of the number of used buckets and the number of allocated buckets,
NT> separated by a slash. This is pretty much useful only to find out
NT> whether Perl's internal hashing algorithm is performing poorly on
NT> your data set. For example, you stick 10,000 things in a hash, but
NT> evaluating %HASH in scalar context reveals "1/16", which means only
NT> one out of sixteen buckets has been touched, and presumably contains
NT> all 10,000 of your items. This isn't supposed to happen. If a tied
NT> hash is evaluated in scalar context, the "SCALAR" method is called
NT> (with a fallback to "FIRSTKEY").
NT> which should be quite enough IMO.
Sounds good. OK
$ perldoc -f scalar|tail -n 4
See perlop for more details on unary operators and the comma
operator.
should also say
See perldata for details on evaluating a hash in scalar contex.
More information about the Perl-maintainers
mailing list