my @thingies = foo() or bar(); warn @thingies; # Expected (3,4) here, got (1)
You got (1)? That would be a bug. I get an empty list, as I expect. foo() returns an empty list, which is assigned to @thingies. bar() is called, but its result is discarded.
my @thingies = ( foo() ) or ( bar() ); warn @thingies; # Expected (3,4) here too, got ()
And rightly so. This is exactly the same expression as the first one. The parens are for precedence only, and a fairly trivial one.
however, with or, why doesn't the first sub get called in list context, return false with the empty list, and let the second sub get called?
But this is exactly what is happening! Perhaps you don't realize the difference between or and ||: precedence. or has a low precedence, lower than assignment. Perhaps you want:
my @thingies = foo (); @thingies = bar () unless @thingies;

Abigail


In reply to Re: Precendence and wantarray puzzling me by Abigail-II
in thread Precendence and wantarray puzzling me by ViceRaid

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.