Scott L Miller <Scott.L.Miller@compaq.com> writes: >In my mind at least, clamping and readonly are 2 different animals. >A hash that has been "clamped" could still have its values modified, >but can't have a new key added, but a hash that is readonly wouldn't >be able to add a key, or have its values modified... Agreed. My "straw man" proposal of how this is implemented is an XS module which turns on _existing_ internal SvREADONLY flag. Thus: use SomeModule qw(readonly); # error messages are not definitve ... my %hash = (a => 1, b => 2); my $ref = \$hash; readonly \%hash; # clamped $hash{'a'} = 10; # okay $hash{'c'} = 30; # dies "Attempt to add key to readonly hash" delete $hash{'b'}; # dies "Attempt to delete key from readonly hash" $ref->{'a'} = 10; # okay $ref->{'c'} = 30; # dies "Attempt to add key to readonly hash" delete $ref->{'b'}; # dies "Attempt to delete key from readonly hash" readonly(\$_) foreach values %hash; # readonly - fix the values $hash{'a'} = 15; # dies "Attempt to modify readonly value" The snag with that is the need to pass reference \%hash to readonly xsub. So a new "operator" could be invented .... > >-Scott L. Miller > >> >I can imagine convincing arguments for semantics that do and don't >> >allow updates via the reference. >> >> I can't. If the hash in readonly/clamped then it does not matter how >> you reach it it is readonly/clamped. >> >> -- >> Nick Ing-Simmons >> http://www.ni-s.u-net.com/ >> -- Nick Ing-Simmons http://www.ni-s.u-net.com/Thread Previous | Thread Next