in reply to Re: new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )
in thread new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )
I care less about the name than the functionality, could be also "count" or whatever suits.
I suppose "elems" is already known from ruby or perl6? So why not.¹
But² tobyinks and your suggestion w/o prototypes is considerably slower on large arrays.
DB<106> use Time::HiRes qw(time) DB<107> sub elems { scalar @_ } DB<108> @a=(1..1e6);0 DB<109> $t=time; $count = scalar @a; print time-$t 7.10487365722656e-05 DB<110> $t=time; $count = elems @a; print time-$t 0.0554749965667725
Perl 5.10!
Cheers Rolf
¹) Well the plural in "elems" somehow indicates a list to be returned.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^3: new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )
by Laurent_R (Canon) on Dec 08, 2012 at 15:46 UTC | |
by Anonymous Monk on Dec 08, 2012 at 16:02 UTC | |
by LanX (Saint) on Dec 08, 2012 at 17:34 UTC |
In Section
Meditations