Because it's not an expression. Expressions evaluate to a value, not statements. Of course, Perl has the oddity that a value can be expected from any statement, but you get weird results if the last statement of a sub or do block is such a statement.
The reason it bothered me is that the return value of given is explicitly documented:
When a given statement is also a valid expression (for example, when it's the last statement of a block), it evaluates to: ...
But of course given is experimental, and I thought it would be nice if it was more clearly defined for the backwards-compatible if.
One shouldn't rely on that.
I'm aware of that for for, but not for if. Source?
In reply to Re^5: printing unitialized value of the 'do BLOCK'
by haukex
in thread printing unitialized value of the 'do BLOCK'
by rsFalse
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |