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');
Copyright © 2002 O'Reilly & Associates. All rights reserved.