"The thing about Perl is that (excluding explicit returns), Perl will return the last value seen in the function. With your "unless" example, the unless is explicitly not going to ever evaluate because the condition is predetermined to be false.
So the entire unless statement is not evaluated and the return is the last evaluation (your variable assignment).
'If' works differently because it does no pre-evaluation. It evaluates the if block every time to determine if the conditional is met. So the last "evaluation" in the function is the if block (which returns nothing, just like your function).
The magic happening is the pre-evaluation conditions of the unless block. Unless ONLY fires if the condition is met. If fires every time, but performs an automatic JMP outside of that block (with a null return) as soon as the condition evals to false."
In reply to Re^2: unless versus if ( ! ) inside a subroutine
by Wheeler
in thread unless versus if ( ! ) inside a subroutine
by Wheeler
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |