in reply to How scoping works in If statements?
for compiler $x is visible outside even though it does operations like case 1. so#case 2: my $x = 5 if (1); print $x; #prints 5
so use braces if u want to make it part of if only.my $x=4 if(1); #x is as good as global for this file. if(1) { my $x=5; # x is visible inside the block for compiler so it makes it +inside. }
|
|---|