in reply to Re^2: How to find number of elements of an array from array reference
in thread How to find number of elements of an array from array reference
Why? Scalar assignment always imposes scalar context.
Perhaps the OP didn't want to do an assignment. Contrast
I find it is seldom necessary to use scalar(), since I'm more likely to do assignment or conditional testing, where scalar context is implied. But scalar() has its place when the default is list context.@a = ( 42 ); printf("%d\n", @a); # prints 42 printf("%d\n", scalar(@a)); # prints 1
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^4: How to find number of elements of an array from array reference
by chromatic (Archbishop) on Apr 07, 2011 at 21:41 UTC |