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

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

Thread Previous | Thread Next
From:
Jeffrey Friedl
Date:
July 19, 2001 12:55
Subject:
Re: [PATCH for discussion] new feature: clamp %hash
Message ID:
200107191955.MAA13383@ventrue.corp.yahoo.com

Graham Barr <gbarr@pobox.com> wrote:
|> > (it's just flipping a bit, so is very low impact).
|> 
|> I am OK with adding, thats not my issue. My issue is with reading the hash.
|> 
|> ie
|> 
|>   $var = $hash{element};
|> 
|> should just continue to return undef, not croak. IMO

The feeling that motivated my wanting all this in the first place probably
was more concerned with prohibiting access to non-existant keys than with
creating new keys, since overall I'd guess that there are more accesses
than assignments. I'd certainly want to protect against typing
	if ($hash{quite}) {
instead of
	if ($hash{quiet}) {
just as I'd want to protect against 
	$hash{quite} = 1;

There's nothing stopping you from accessing any element you'd like (so
Perl's not forcing anything), but if you *do* want access limitiations to
what's currently there, I'd feel symmetrical restrictions make the most
sense.

And, since you can temporarily unclamp, it doesn't remove the functionality
you wish (it just makes it ugly). But to go the other way actually lowers
the overall functionality.

Here's an idea. It should be trivial to have two clamping bits:

 clamp %hash, CLAMP_CREATE;
 clamp %hash, CLAMP_ACCESS;
 clamp %hash, CLAMP_ACCESS|CLAMP_CREAT;
 clamp %hash, CLAMP_ALL; # same as CLAMP_ACCESS|CLAMP_CREAT
 clamp %hash, CLAMP_NONE;

Jeffrey

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