Paul Johnson <[email protected]> writes:
> On Mon, Jan 25, 2016 at 12:24:04AM +0100, lee wrote:
>> Paul Johnson <[email protected]> writes:
> [...]
>> Consider with these examples that an expression like (1, 3) might
>> unexpectedly evaluate to 3, and you start to think that you don't like
>> things like
>>
>>
>> sub s {
>> my $a = 1;
>> my $b = 3;
>>
>> return ($a, $b);
>> }
>>
>>
>> anymore because you could, by mistake (or intentionally), write
>>
>>
>> my $x = s;
>>
>>
>> . So let me re-phrase my original question to: How do you /safely/
>> return arrays?
>>
>> That means I need an error message for '$x = s;' because I'd write that
>> only by mistake.
>
> You could add to your subroutine:
>
> die "Only call in list context" unless wantarray;
Oh, that's really cool :)
--
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]
http://learn.perl.org/