Beefy Boxes and Bandwidth Generously Provided by pair Networks
more useful options
 
PerlMonks  

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!
chas

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.)
      chas

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (4)
As of 2020-10-20 06:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My favourite web site is:












    Results (209 votes). Check out past polls.

    Notices?