damien krotkine <dkrotkine@gmail.com> wrote:
That can be a good idea, but we should be extremely cautious with ties : they are slow, and a bit magic.
Another possibility would be to use lock_hash() from Hash::Util (core since Perl 5.8.0); that forbids modification of the hash, but in a way that doesn't affect lookup speed. The only downside is that you can still modify arrays and hashes that are stored (by reference) in the hash: use Hash::Util qw<lock_hash>; my %hash = (array => [], hash => {}, string => 'foo'); lock_hash(%hash); push @{ $hash{array} }, 1; # allowed $hash{hash}{nested}++; # allowed $hash{string} = 1; # forbidden (replaces a stored value) $hash{new_key} = 1; # forbidden (adds a key) delete $hash{array}; # forbidden (deletes a key) -- Aaron Crane ** http://aaroncrane.co.uk/