@a = @b || @c; # this is wrong @a = scalar(@b) || @c; # really meant this
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.

I have constructed the following test to show that you can use 'or' in list context.

Update: I have realized my error in the code below. The line my @c = @a or @b was wrong, it was not behaving as what I have expected, it was really doing this instead: (my @c = @a) or @b;. Ok, another lesson for me on precedence and misconception about the 'or' operator.

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);
And the output is as expected -
$VAR1 = [ 1, 2, 3 ];
jweed's problem wasn't on how he used the 'or', but rather how he used the brackets. Consider the following example:

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);
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 -

$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

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.