in reply to Confusion over scope of "my" vars

The behaviour of

my $x = 0 if 1 == 2;

is documented as undefined.

The problem is that you get the compile-time effect of my (declaring the variable) without the run-time effect (clearing the variable).

Lexicals variables are permanently allocated. They are cleared on scope exit, not freed.

The recursive effects are related to existence of a copy of the lexicals for every layer of recursion.

sub f { my ($n) = @_; my $x if 0; print ++$x, "\n"; f($n-1) if $n>1; } f(3); # 1,1,1 f(2); # 2,2 f(3); # 3,3,2

Update: Added bit about recursion.