Yes, that appears to be what's happening:

C:>perl -le "sub u { unless(shift) { 'false' } }; print u($_) for unde +f, '', 0..3" false false false 1 2 3 C:>perl -le "sub i { if(shift) { 'true' } }; print i($_) for undef, '' +, 0..3" 0 true true true

I'm not sure if it's meeting the technical definition of "expression" from "If no return is found and if the last statement is an expression, its value is returned"... but the last statement executed was the failed if or unless, and as part of that execution of that statement, the CONDITIONAL expression had to be evaluated, so I can definitely see a good case for why that EXPR's value is what is returned. But since I couldn't find a perl-specific definition of "expression" (and it appears it's been a longstanding lack of definition, because as far back as 2001, people were asking What is the difference between a Statement and an Expression? without getting a canonical answer from the perl documents), there is wiggle-room in the interpretation of whether the documents claim the return value is unspecified or not.

Interesting sub-discussion. Thanks!


In reply to Re^8: resetting a foreach loop! by pryrt
in thread resetting a foreach loop! by lunette

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.