in reply to Re^2: unless versus if ( ! ) inside a subroutine
in thread unless versus if ( ! ) inside a subroutine

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.