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

Re: [PATCH for discussion] new feature: clamp %hash

Thread Previous | Thread Next
Jeffrey Friedl
July 19, 2001 17:03
Re: [PATCH for discussion] new feature: clamp %hash
Message ID:

schwern  <> wrote:
|> On Thu, Jul 19, 2001 at 11:15:12AM -0700, Jeffrey Friedl wrote:
|> > I added a new reserved word (I can hear the cringing already) "clamp".
|> Here's my thoughts about any new attempt to replace pseudo-hashes,

My thought of clamp has never been that they are somehow a replacement for
pseudo-hashes. They're sort of apples and oranges (although both are orbed

|> sort of a minimal requirement set.
|> 1)  They should act *just like regular hashes* except in that their keyset
|>     is fixed.

I agree.

But, I don't think this is relevent to 'clamp'.

My idea is that clamp is simple: it makes it an error to add and/or access
keys that are not currently there. That's it. It's a new feature for normal

It's very lightweight.

Since you can unclamp (or declamp, or whatever) something, it doesn't
provide security or anything. Just think of it as a kind of 'use strict'
for hash keys: with 'clamp' and some minimal setup, you protect yourself
from typos and the like. This is similar to 'use strict' and having to
declare your variables. In either cases, the result is wonderful when
used appropriately, a nightmare when not.

|> clamp() unfortunately violates this.  You have to put all your keys in
|> the hash before clamping it, so there's effectively no way to
|> distinguish between a valid key which has not been set yet and a valid
|> key which is set to undef


|> clamp() looks to be just as fast as regular hashes.

Clamped hashes _are_ regular hashes -- just regular hashes with certain
restrictions. The whole point of adding 'clamp' is to be able to add these
restrictions. At least that's what I'm thinking......


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