home | O'Reilly's CD bookshelfs | FreeBSD | Linux | Cisco | Cisco Exam  

Book HomeJava and XSLTSearch this book

8.119. 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);

# Now, try to set %hash{'something'}
while(my($key, $value) = each %hash) {
    print "$key -> $value\n";


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');

Library Navigation Links

Copyright © 2002 O'Reilly & Associates. All rights reserved.