Hash::Util
Offers a selection of general-utility hash subroutines. Starting with Perl 5.8, hashes allow you to restrict access to the data that’s stored in the hash. Individual keys can be locked so they cannot be deleted, nor can their values be changed. Hash::Util is largely intended to replace the deprecated pseudo-hashes.
For example:
#!/usr/local/bin/perl -w %hash = (foo => 42, bar => 23); lock_keys(%hash); # Now, try to set %hash{'something'} while(my($key, $value) = each %hash) { print "$key -> $value\n"; } unlock_keys(%hash);
You can lock specific values as follows:
#!/usr/local/bin/perl -w %hash = (foo => 42, bar => 23); lock_key(%hash, 'foo'); # Now, try to set 'foo' and see what happens unlock_keys(%hash, 'foo');
Get Perl in a Nutshell, 2nd Edition now with the O’Reilly learning platform.
O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.