Re: FAQ 4.58 How can I know how many entries are in a hash?
- From: Joost Diepenmaat <joost@xxxxxxxxx>
- Date: 13 Dec 2007 13:18:16 GMT
On Thu, 13 Dec 2007 05:01:22 -0800, Todd wrote:
$num_keys = keys %hash;
Seems there is a better way to do it:
#! /bin/perl -l
%hash = (a=>1, b=>2, c=>3, d=>4, e);
$num_keys = %hash+0;
I fail to see how this qualifies as "better".
[..]
So it means when in numeric(not string) context, %hash return numbers of
keys accidently. But anyway, it's a good feature.
This is indeed accidental, and as far as I know not guaranteed to work in
any future version of perl. It's also unlikely to work with tied hashes.
Joost.
.
- Follow-Ups:
- References:
- FAQ 4.58 How can I know how many entries are in a hash?
- From: PerlFAQ Server
- Re: FAQ 4.58 How can I know how many entries are in a hash?
- From: Todd
- FAQ 4.58 How can I know how many entries are in a hash?
- Prev by Date: Re: FAQ 4.58 How can I know how many entries are in a hash?
- Next by Date: Re: Next Page gets downloaded in Perl
- Previous by thread: Re: FAQ 4.58 How can I know how many entries are in a hash?
- Next by thread: Re: FAQ 4.58 How can I know how many entries are in a hash?
- Index(es):
Relevant Pages
|