The third case reads to Perl like so:
($a,$b) = ( qw/a b/ || die );

Note that the || gets to be evaluated first. Since the boolean logic operators force scalar context on their left hand operand, which in this case is a list, you get what a list returns when coerced into scalar context: its last element. This is the string b here. Because it is is a true value, it shortcircuits the or-operator and so prevents die from being called. Now we get to the assignment, with just a single value in hand. The $a slurps it up, and $b is left with nothing to take.

By changing the order of evaluation with an extra pair of parens, you can make sure the or-operator doesn't coerce the wrong thing into scalar context - just like you did in your case #1.

Makeshifts last the longest.


In reply to Re: question about || operator and list context by Aristotle
in thread question about || operator and list context by markjugg

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.