Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^12: Making a variable in a sub retain its value between calls

by TimToady (Parson)
on Apr 19, 2005 at 16:28 UTC ( [id://449318]=note: print w/replies, xml ) Need Help??


in reply to Re^11: Making a variable in a sub retain its value between calls
in thread Making a variable in a sub retain its value between calls

INIT blocks are not evil--they're just broken in Perl 5, which is why they'll work right in Perl 6. An INIT should just run as soon as possible, but not before the run-time process starts. It should never be "too late" to run an INIT.

On the other hand, going back to the OP's question, INIT is not the Perl 6 solution to that. Instead, we'll use state variables, which have FIRST semantics rather than INIT semantics. That lets closure clones get individual state variables with individual initializations, but makes Perl keep track of "first use" for the user. INIT is just too blunt of an ax for that purpose.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2024-04-26 06:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found