Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
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.