in reply to new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )
size is a terrible name, because it doesn't imply any unit. It could stand for string length in characters, string length in bytes, used memory, number of allocated elements in a container, number of actual elements in a container or any other size you can think of.
It makes sense to you now because it's not too bad in the mental context you are in, but from the outside it's not good.
Anyway, if you don't fiddle with prototypes at all, the argument list of a subroutine is automatically in list context, so you can just write
sub elems { scalar @_ }
and don't need a new keyword at all.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: new keyword "size" to avoid scalar trap ? ( scalar @array != scalar(LIST) )
by LanX (Saint) on Dec 07, 2012 at 17:28 UTC | |
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 |