Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation

Re^2: Interview Prepration

by chas (Priest)
on Apr 03, 2005 at 20:44 UTC ( #444526=note: print w/replies, xml ) Need Help??

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!

Replies are listed 'Best First'.
Re^3: Interview Prepration
by cog (Parson) on Apr 03, 2005 at 20:47 UTC
    I learned about this from the book "Effective Perl Programming"

    I'm in the middle of a bunch of Perl books (I always am).

    Coincidentally, that's one of them :-) Guess I didn't reach that part yet... :-)

      Me too, and I often go back and read over the ones I've read in the past. It's like watching a movie the second time - you pick up things you missed before. I have one of the first versions of "Effective Perl Programming". The discussion about "my" and "local" is in the chapter on subroutines. Along with typeglobs, it seems one of the more subtle less understood notions in Perl. (My understanding is only partial, for sure.)

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://444526]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others wandering the Monastery: (2)
As of 2021-06-14 11:48 GMT
Find Nodes?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)

    Results (62 votes). Check out past polls.