develooper Front page | perl.perl5.porters | Postings from March 2023

Re: Pre-RFC Deep constants

Thread Previous | Thread Next
From:
demerphq
Date:
March 12, 2023 21:44
Subject:
Re: Pre-RFC Deep constants
Message ID:
CANgJU+WJ4BnCqjuRWt=gwif-HOLqQUfPBQ=-XXVAU4io6KGdXg@mail.gmail.com
On Sun, 12 Mar 2023 at 16:25, demerphq <demerphq@gmail.com> wrote:

> On Sat, 11 Mar 2023 at 16:50, demerphq <demerphq@gmail.com> wrote:
>
>> Like I said, it turns out that reasonable people can disagree on what a
>> constant hash should be. :-) I really wish we didnt have restricted hashes
>> getting in the way, simple "readonly" hashes would be much more useful than
>> restricted hashes are.
>>
>> MMMM, I wonder if there is a way we can extend restricted hashes so they
>> behave as people would expect a readonly/constant hash to behave without
>> throwing out restricted hashes entirely. Maybe something like
>> lock_hash(\%hash, undef); ? Eg, the undef would signal "allow any key".
>> Hrmmmm...... Watch this space, maybe I can come up with a hack for this.
>>
>
> Turns out the important part of this is easy to do. I have a POC working
> on my local build, I will push a patch in the next day or two.
>

https://github.com/Perl/perl5/pull/20928

Effectively Hash::Util::protect_hash_recursive() can be used to create a
"constant hash", including anything it contains.

It needs more testing which is why the pull is marked as draft.

cheers,
Yves

-- 
perl -Mre=debug -e "/just|another|perl|hacker/"

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