home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!usc!news.cerf.net!netlabs!lwall
- From: lwall@netlabs.com (Larry Wall)
- Subject: Re: How do I find the size of an associative array?
- Message-ID: <1993Jan21.193225.16634@netlabs.com>
- Sender: news@netlabs.com
- Nntp-Posting-Host: scalpel.netlabs.com
- Organization: NetLabs, Inc.
- References: <1993Jan21.011148.10908@kpc.com>
- Date: Thu, 21 Jan 1993 19:32:25 GMT
- Lines: 15
-
- In article <1993Jan21.011148.10908@kpc.com> hollasch@kpc.com (Steve Hollasch) writes:
- : What's the best method to find the number of elements in an associative
- : array? The following works, but seems rather cumbersome:
- :
- : @list = keys %aa;
- : num_elements = $#list + 1;
- :
- : It seems that this would be inefficient since it implies scanning through
- : the whole array and copying the keys into a list. Isn't there a quicker
- : way?
-
- In recent Perl you can say $num_elements = keys %aa. It still has to scan
- (as of 4.035), but at least you save copying the keys around.
-
- Larry
-