Hang on, shouldn't you be using 'or' instead? '||' works in scalar context, while 'or' also works in list context. jweed didn't say that he used '||', he used 'or' instead in his program.@a = @b || @c; # this is wrong @a = scalar(@b) || @c; # really meant this
And the output is as expected -use strict; use Data::Dumper; my @a = (1, 2, 3); my @b = (4, 5, 6); my @c = @a or @b; # equivalent to (my @c = @a) or @b; print Dumper(\@c);
$VAR1 = [ 1, 2, 3 ];
The line my @d = (@a or @b) is 'logically wrong', because the brackets force what's inside to be evaluated in scalar context. The output of the above program is -use strict; use Data::Dumper; my @a = (1, 2, 3); my @b = (4, 5, 6); my @c = @a or @b; my @d = (@a or @b); print Dumper(\@c); print Dumper(\@d);
$VAR1 = [ 1, 2, 3 ]; $VAR1 = [ 3 ];
In reply to Re: Re: Short circut operators in list context
by Roger
in thread Short circut operators in list context
by jweed
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |