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

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

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
August 1, 2001 09:17
Subject:
Re: [PATCH for discussion] clamp, round #2
Message ID:
20010801161743.1751.10@bactrian.ni-s.u-net.com
Jeffrey Friedl <jfriedl@yahoo.com> 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, 

Why?

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


>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
http://www.ni-s.u-net.com/


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