Subject: | Feature: new routine count() |
It would be useful to have a routine count() which counts the number of elements in a list. The simplest implementation is as
sub count { scalar @_ }
Further optimizations are possible with XS code, but the above should be enough.
You may wonder why this is necessary - there is some discussion at
<http://thread.gmane.org/gmane.comp.lang.perl.perl5.porters/134968/>.
Long story short, most of the idioms or tricks suggested to get the number of elements in a list don't actually work for all cases. This can lead to fragile code
when beginners pick up scalar(...) or other not-quite-working constructs and think
that this is the way to count elements. A guaranteed working way to count a list
would be a most welcome addition to List::MoreUtils.