Hi

I'm perplexed; I'm using CGI to receive a list of parameters, which might arrive under one name or another. So I wrote:

my @things = $q->param('t') or $q->param('things');

I wanted the list of parameters in t, or if that parameter is absent, the ones in things. It's all good if t is present, but fails otherwise, with an empty list. I narrowed it down to the following test case:

sub foo { wantarray ? () : 1; } sub bar { wantarray ? (3, 4) : 3; } my @thingies = foo() or bar(); warn @thingies; # Expected (3,4) here, got () my @thingies = ( foo() ) or ( bar() ); warn @thingies; # Expected (3,4) here too, got ()

I don't understand! If I were using ||, sure, that puts the calls in scalar context; 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? What am I missing?

Thanks
ViceRaid

update: fixed cut-and-paste mistakio in code results comment, as pointed out by Abigail-II


In reply to 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.