in reply to Return Value of List-Producing Elements in Scalar Context
Normally, $a = @array; will store the number of elements in the list in $a. That is not always the case, because of wantarray. For example:
$scalar = localtime(); print($scalar, "\n"); # "Mon Aug 23 11:31:16 2004" @array = localtime(); $scalar = @array; print($scalar, ':', join(',', @array), "\n"); # 9:16,31,11,23,7,104,1,235,1 @array = scalar(localtime()); $scalar = @array; print($scalar, ':', join(',', @array), "\n"); # 1:Mon Aug 23 11:34:30 2004
Update: Fixed error pointed out by davorg
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Return Value of List-Producing Elements in Scalar Context
by davorg (Chancellor) on Aug 23, 2004 at 15:38 UTC | |
by ikegami (Patriarch) on Aug 23, 2004 at 15:43 UTC |