[BristolBathPM] Perl 6 "elems"

Colin M. Strickland cms at beatworm.co.uk
Sun Jun 21 08:33:08 BST 2009


On 21 Jun 2009, at 01:09, Jamie Lokier wrote:

> I find @array in scalar context a nice way to get the
> number of elements in Perl 5, though it is a bit too implicit for the
> unfamiliar reader.

It doesn't have to be implicit though. A common pattern is to lob in a  
literal 'scalar' to make it explicit e.g. $count = scalar @things;

I'm not sure it's particularly readable, and the useless invocation of  
scalar is possibly not optimal, but it unambiguously indicates that  
there's some kind of transforming operation in there.

-- 
Regards,
Colin M. Strickland



More information about the BristolBathPM mailing list