home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- Path: sparky!uunet!cs.utexas.edu!usc!sdd.hp.com!ux1.cso.uiuc.edu!news.cso.uiuc.edu!ux2.cso.uiuc.edu!ejk
- From: ejk@ux2.cso.uiuc.edu (Ed Kubaitis - CCSO)
- Subject: Re: fast way to get number of elements in an assoc array?
- References: <1992Aug27.032106.20515@CS.ORST.EDU>
- Message-ID: <BtnIDn.390@news.cso.uiuc.edu>
- Sender: usenet@news.cso.uiuc.edu (Net Noise owner)
- Organization: University of Illinois - Urbana
- Date: Thu, 27 Aug 1992 16:41:42 GMT
- Keywords: associative array number count $#array $#
- Lines: 25
-
- jacobsd@prism.cs.orst.edu (Dana Jacobsen) writes:
- |
- | Is there a function akin to $#array that works on associative arrays? I
- |have an associative array with over 30,000 keys, and this is what I'm
- |currently doing:
- |
- | @dummykey = keys(%records);
- | print $#dummykey+1, " records loaded.\n";
- | undef (@dummykey);
- |
- | The problem with this is that the key list takes up a significant chunk of
- |memory, as well as being very slow. The alternative way of handling this is
- |to keep a seperate variable that contains the number of elements in the
- |array...
-
- From perl 4.0 patch #20:
-
- |Subject: scalar keys %array now counts keys for you
-
- So 'scalar(keys(%records))' or '$nkeys = keys(%records);' should work on
- perl beyond 4.019. Don't know how fast it is on large arrays, though.
-
- ----------------------------------
- Ed Kubaitis (ejk@ux2.cso.uiuc.edu)
- Computing & Communications Services Office - University of Illinois, Urbana
-