home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / comp / lang / perl / 7935 < prev    next >
Encoding:
Text File  |  1993-01-21  |  1007 b   |  28 lines

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