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

Re: [PATCH for discussion] clamp, round #2

Thread Previous | Thread Next
Nick Ing-Simmons
August 1, 2001 09:17
Re: [PATCH for discussion] clamp, round #2
Message ID:
Jeffrey Friedl <> writes:
>For two distinct reasons:
>   1) Even if a hash is completely readonly,
>	 if ($hash{NonExistantKey})
>      does not create the key, and so is permitted.

Says you - but suppose it wasn't? that is in a clamped hash any access
to a non-existant key (except via exists) "died". 

>      One may want the additional ability to prohibit this kind of access
>      to random keys (i.e. to flag them as an error -- my {quite}/{quiet}
>      example).
>   2) One may wish to prohibit the reading of non-existant keys
>      w/o prohibiting the creation of them. 

Hmm - begining to get it.

>|> "magic" calls C code when you (attempt to) access something. 
>|> e.g. "tie" adds magic that pushes things onto stack and calls methods
>|> when access is attempted. The cost of the 'magic' part is low,
>|> the high cost of 'tie' is the stack twiddling and the method lookup.
>I suppose one could make a copy of all the current hash stuff, 


>put it
>behind a magic call, then make the few minor changes needed to support this

>It seems like a lot of duplicated code to save a very small amount,
>but maybe it's that kind of attitude that makes Perl so fast.

No. Write C code that does the tests to support all this stuff.
If test permit the access call existing hash code, else croak().
Install as magic vtable when requested by user API.

No replication required. In addition magic comes with extra space to store
the "flags" ...

>	Jeffrey
Nick Ing-Simmons

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