http://www.perlmonks.org?node_id=444526


in reply to Re: Interview Prepration
in thread Interview Prepration

"2. Explain the difference between my and local.
I'm not sure but I think I heard someone say it was kind of the same thing, internally... I
"
There is actually a significant difference. "my" creates lexically scoped variables (e.g. existing within a block.) "local" variables have run-time scoping; "local" saves the (previously defined) values of arguments on a stack and later restores them, using the "locally defined" values during some containing scope. Changes made by "local" to global variables can be visible outside the lexical scope of the "local" variables e.g. in nested subroutine calls. I learned about this from the book "Effective Perl Programming" by Joseph Hall, and Randal Schwartz (Addison Wesley Publ.) Highly recommended!
chas