So the entire unless statement is not evaluated and the return is the last evaluation (your variable assignment).

This is not exactly true.

sub t1 { my $v = 'last expression'; my $x = 'last assignment'; unless ( $v ) {} } sub t2 { my $x = 'last assignment'; unless ( 'last expression' ) {} } printf "t1 returns [%s]\n", t1(); printf "t2 returns [%s]\n", t2(); __END__ t1 returns [last expression] t2 returns []

Looking at the output from B::Deparse, It seems the first unless is left as-is, but the second one (where the condition is a literal) is reduced to !1 (which returns as the empty string).

If I change each unless to if, the second one reduces the same way, and the first one stays (just like the first unless stays originally).

So I think the rest of your email response is suspect also. In my testing, if seems to evaluate the same way as unless.


In reply to Re^3: unless versus if ( ! ) inside a subroutine by kyle
in thread unless versus if ( ! ) inside a subroutine by Wheeler

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.