go ahead... be a heretic | |
PerlMonks |
Re^2: Interesting: a genuine Perl-bugby liverpole (Monsignor) |
on Sep 23, 2010 at 00:21 UTC ( [id://861412]=note: print w/replies, xml ) | Need Help?? |
Hi sundialsvc4,
It's a very cool feature of 5.10 which mimics the static variable of C. State variables don't lose their data, even when they go out of scope, so you can use them for cases where you want data to persist, without having to use globals. For example, to perform initialization only once the first time a subroutine is called, you could do this:
Or to define a subroutine which returns a unique integer each time it's called:
s''(q.S:$/9=(T1';s;(..)(..);$..=substr+crypt($1,$2),2,3;eg;print$..$/
In Section
Seekers of Perl Wisdom
|
|