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

Re: A 'permanent' keyword

Thread Previous | Thread Next
From:
Tom Molesworth via perl5-porters
Date:
November 12, 2021 03:47
Subject:
Re: A 'permanent' keyword
Message ID:
CAGXhHdnFkXZzJHP9CNQ5cefjJX6E2kVtY5HNNKb68h9gw=Pi9w@mail.gmail.com
+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


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About