Re: Find the number of elements in a hash.

2001-06-05 Thread Jeff 'japhy' Pinyan
On Jun 5, Paul said: >> > 3/8 >> >> No, it means 3 out of the 8 buckets allocated have been used. This >> doesn't tell you the number of keys, unless (by some terrible >> misfortune) all your keys have found their way into unique buckets. > >Another thing -- does it always tell you how many buc

RE: Find the number of elements in a hash.

2001-06-05 Thread Paul
I would recommend the other answers over my own. my $cnt = scalar keys %hash; seems more readable to me. Paul --- Doug Johnson <[EMAIL PROTECTED]> wrote: > Perfect! Thanks a million.. > > Doug > > > > --- Doug Johnson <[EMAIL PROTECTED]> wrote: > > In an array to find the number of elem

Re: Find the number of elements in a hash.

2001-06-05 Thread Paul
--- Jeff 'japhy' Pinyan <[EMAIL PROTECTED]> wrote: > On Jun 4, Paul said: > > > 3/8 > > > >Which means there are 3 elements, and space has been allocated for > 8. > > No, it means 3 out of the 8 buckets allocated have been used. This > doesn't tell you the number of keys, unless (by some terri

Re: Find the number of elements in a hash.

2001-06-04 Thread Tom Allen
This goes right along with my problem. How can you tell how much memory (RAM) the hash takes? - Original Message - From: "Doug Johnson" <[EMAIL PROTECTED]> To: <[EMAIL PROTECTED]>; <[EMAIL PROTECTED]> Sent: Monday, June 04, 2001 5:04 PM Subject: RE: Find the

RE: Find the number of elements in a hash.

2001-06-04 Thread Doug Johnson
Perfect! Thanks a million.. Doug --- Doug Johnson <[EMAIL PROTECTED]> wrote: > In an array to find the number of elements in an array I : > > print "$#array\n"; > > Is there a similar way to find the number of keys in a hash without > cycling through them and without assigning the hash to

Re: Find the number of elements in a hash.

2001-06-04 Thread Jeff 'japhy' Pinyan
On Jun 4, Paul said: > 3/8 > >Which means there are 3 elements, and space has been allocated for 8. No, it means 3 out of the 8 buckets allocated have been used. This doesn't tell you the number of keys, unless (by some terrible misfortune) all your keys have found their way into unique buckets

Re: [OT] Find the number of elements in a hash.

2001-06-04 Thread Paul
--- "Brett W. McCoy" <[EMAIL PROTECTED]> wrote: > On Mon, 4 Jun 2001, Doug Johnson wrote: > my $key_count = keys %HASH; Doh. I've DONE that, and still posted that stupid suggestion. =o) = print "Just another Perl Hacker\n"; # edited for readability =o) ==

Re: Find the number of elements in a hash.

2001-06-04 Thread Paul
--- Doug Johnson <[EMAIL PROTECTED]> wrote: > In an array to find the number of elements in an array I : > > print "$#array\n"; > > Is there a similar way to find the number of keys in a hash without > cycling through them and without assigning the hash to an array? You can print the hash in

Re: Find the number of elements in a hash.

2001-06-04 Thread Brett W. McCoy
On Mon, 4 Jun 2001, Doug Johnson wrote: > In an array to find the number of elements in an array I : > > print "$#array\n"; Nope, not quite. It returns the index of the last element. Putting your list in a scalar context is a better way: my $array_cnt = @array This is what foreach does when

Re: Find the number of elements in a hash.

2001-06-04 Thread Mathew Hennessy
Doug Johnson wrote: > > Is there a similar way to find the number of keys in a hash without cycling > through them and without assigning the hash to an array? Dunno if you can avoid counting them, but $keycount = keys(%hash) will do what you want. Hopefully there's an optimization somew

Find the number of elements in a hash.

2001-06-04 Thread Doug Johnson
In an array to find the number of elements in an array I : print "$#array\n"; Is there a similar way to find the number of keys in a hash without cycling through them and without assigning the hash to an array? Doug