develooper Front page | perl.perl5.porters | Postings from November 2021

Re: A 'permanent' keyword

Thread Previous | Thread Next
Tom Molesworth via perl5-porters
November 12, 2021 03:47
Re: A 'permanent' keyword
Message ID:
+1 on the documentation suggestion - maybe pull some of the perlsub content
into perldoc -f state, since I think that covers the behaviour pretty well?

    If a state variable resides inside an anonymous subroutine, then
    each copy of the subroutine has its own copy of the state variable.
    However, the value of the state variable will still persist between
    calls to the same copy of the anonymous subroutine. (Don't forget that
    "sub { ... }" creates a new subroutine each time it is executed.)

If we do add a keyword/CPAN module for this, would suggest `permanent`
isn't ideal - the two concepts I'd expect for that keyword would either be:

- constant
- or refcount of -1

and for me "state but shared between other instances of this CV" would be a
long way down the list of "what might this mean"!

I don't have a better name - `sharedstate` or `singletonstate` maybe.

Thread Previous | Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About