Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: my and local variable significance in a particular case

by GrandFather (Sage)
on Apr 24, 2012 at 05:38 UTC ( #966730=note: print w/replies, xml ) Need Help??

in reply to my and local variable significance in a particular case

Lexical variables are scoped to the current block (which may be the entire file and in the sample case) and must be declared using my. local, as you say, tucks away the previous value of something (it need not be a package variable btw) and restores it when the current scope is exited.

I suspect you pretty much already knew that. Maybe the missing piece is that you should generally use my (lexical variables) unless you need the extra behaviour that local provides. local doesn't give the scoping protection that a lexical variable does and it incurs some runtime overhead. Bottom line: if you want a variable that is scoped to the current block use a lexical variable.

True laziness is hard work
  • Comment on Re: my and local variable significance in a particular case

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://966730]
[1nickt]: the tick that can make you a vegetarian
[perldigious]: Your Mother: Yeah, I have a tool for ticks that I use (mostly on my dogs thankfully), but it's just a cheapo one I got from my vets office... it works pretty good though.
erix saw a tick in a natural history museum collected from the scrotum of the curator (it was removed)
[Your Mother]: The exhibit, the tick, or the scrotum?
[erix]: (the man is even a paleontologist )
[1nickt]: erix unfortunately that's there favourite spot. That's why they are usually spotted crawling *up* your leg.
[erix]: ha, the tick and, as it happens, also the curator (now a professor of Paleont.)
[1nickt]: s/there/their/, ugh sorry.
[Your Mother]: Heh. The only one I ever had on me, I caught on my shin, headed north.
erix looks nervously I got away cleanly from my run , it seems :)

How do I use this? | Other CB clients
Other Users?
Others meditating upon the Monastery: (15)
As of 2017-05-24 13:16 GMT
Find Nodes?
    Voting Booth?