3 ms·
You’re right that Python only has function scope, not quite lexical scope. But perl -e ' sub foo { $x = 42 } foo; print "\$x is $x\n"; ' quiet
by erik_seaberg 6y ago
You’re right that Python only has function scope, not quite lexical scope. But
perl -e '
sub foo { $x = 42 }
foo;
print "\$x is $x\n";
'
quietly creates a global variable. You have to ask for lexical scope, and you have to ask for strict mode to get that error (requiring 5.11 or better does that, but merely having 5.11 does not). Backward compatibility justifies this but devs need to beware this is how the language used to be.