in reply to Re^5: Local for lexicals
in thread Local for lexicals
Well, sort of... what I would say is the key feature of "dynamic scoping" is that if you call some other sub it sees the current localized value of the variables. E.g. if you do this:
Is it really the case that setting aside a value to be restored at the end of scope is what is meant by “dynamic scoping”?
then any print statements buried down in the print_data sub will now have tabs automatically appended to them.
print_data( \@data );
With lexical scoping, if you say
then inside the block you get a new variable that happens to have the same name as $some_variable, and you see that new variable only inside of the block you're looking at... you don't have to worry about there being any far-ranging effects inside of the sub do_some_stuff.
my $some_variable = 1;
my $some_variable = 0;
Does that help?