Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: 'my' and 'state' declaration inside a loop

by GrandFather (Cardinal)
on Aug 07, 2012 at 20:32 UTC ( #986074=note: print w/ replies, xml ) Need Help??


in reply to Re: 'my' and 'state' declaration inside a loop
in thread 'my' and 'state' declaration inside a loop

state is not an 'improvement' of my. It is an improvement of Perl to provide a small feature that was missing - scoped static variables. The common part between my and state variables is that they can't be accessed by name outside their lexical scope. The prime difference between them is that my variables get a fresh chunk of memory each time their lexical scope is entered whereas static variables are assigned a chunk of memory at program start time and retain it until execution terminates.

True laziness is hard work


Comment on Re^2: 'my' and 'state' declaration inside a loop

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (8)
As of 2014-09-22 15:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (198 votes), past polls