develooper Front page | perl.perl5.porters | Postings from October 2001

Re: Clamp, wherefor art thou

Thread Previous | Thread Next
Jeffrey Friedl
October 30, 2001 13:22
Re: Clamp, wherefor art thou
Message ID:

Jarkko Hietaniemi <> wrote:
|> What I'd like to see is at least two separate patches:
|> (1) Adding the SvREADONLY logic for hashes
|> (2) The allowable set of keys.

As far as the core goes, these two really do go hand in hand, and I really
do think that the patch I submitted earlier takes care of it well. (I'll
extend it to arrays later this evening.)

The semantics we have now, as developed in the previous thread:

   * you can mark the set of hash keys to be readonly (no deletes or adds)
     [if you want the whole hash to be readonly, walk it and mark the
      scalars readonly]

   * you can freeze the set of allowable keys (which means you can add
     and subtract keys, but only within a previously-defined set of keys)

It's the desire for that last feature that has been driving all this for me.
The way it's done is that when you clamp (or whatever you want to call it)
the hash, the keys that exist at the time are the ones allowed. So, you
can preload the keys you want to be allowed, clamp it, then delete the keys
you don't want to actually exist. This might be done in an object constructor,
to limit the keys that can ever be part of the hash representing the object
(so that you don't use $obj->{Quite} when you intended to use $obj->{Quiet}).

|>     (I also have to agree with Nick that 'clamp' doesn't do it for me.)

I don't care what it's called. That name appears only in a few places in the
code, and need never be exported to the user. I'm happy to call it anything
anyone wants......


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