mildside has asked for the wisdom of the Perl Monks concerning the following question:
return wantarray ? @my_array : scalar @my_array;as opposed to just:
return @my_array;when the sub is called in a scalar context?
If an array is returned from a sub in a scalar context, does the conversion to a scalar happen before returning (thus returning a scalar) or after (thus returning an array and converting to scalar)?
I would have guessed that Perl was smart enough to do the former, but I have seen the simple wantarray code above used a few times and I'm wondering if it is really necessary.
Thanks in advance, and Cheers!
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: returning arrays from a sub - how clever is Perl?
by pg (Canon) on Oct 21, 2003 at 23:42 UTC | |
by Roger (Parson) on Oct 22, 2003 at 00:15 UTC | |
by davido (Cardinal) on Oct 22, 2003 at 04:55 UTC | |
|
Re: returning arrays from a sub - how clever is Perl?
by davido (Cardinal) on Oct 22, 2003 at 00:33 UTC | |
by revdiablo (Prior) on Oct 22, 2003 at 03:47 UTC | |
by mildside (Friar) on Oct 22, 2003 at 03:55 UTC | |
by hardburn (Abbot) on Oct 22, 2003 at 13:47 UTC | |
|
Re: returning arrays from a sub - how clever is Perl?
by mildside (Friar) on Oct 22, 2003 at 00:26 UTC |