hash::util(3)
NAME
Hash::Util - A selection of general-utility hash subrou
tines
SYNOPSIS
use Hash::Util qw(lock_keys unlock_keys
lock_value unlock_value
lock_hash unlock_hash);
%hash = (foo => 42, bar => 23);
lock_keys(%hash);
lock_keys(%hash, @keyset);
unlock_keys(%hash);
lock_value (%hash, 'foo');
unlock_value(%hash, 'foo');
lock_hash (%hash);
unlock_hash(%hash);
DESCRIPTION
"Hash::Util" contains special functions for manipulating
hashes that don't really warrant a keyword.
By default "Hash::Util" does not export anything.
Restricted hashes
5.8.0 introduces the ability to restrict a hash to a cer
tain set of keys. No keys outside of this set can be
added. It also introduces the ability to lock an individ
ual key so it cannot be deleted and the value cannot be
changed.
This is intended to largely replace the deprecated
pseudo-hashes.
- lock_keys
unlock_keys - lock_keys(%hash);
lock_keys(%hash, @keys); - Restricts the given %hash's set of keys to @keys. If
@keys is not given it restricts it to its current key
set. No more keys can be added. delete() and
exists() will still work, but it does not effect the set of allowed keys.
unlock_keys(%hash;)- Removes the restriction on the %hash's keyset.
- lock_value
unlock_value - lock_key (%hash, $key);
unlock_key(%hash, $key); - Locks and unlocks an individual key of a hash. The
value of a locked key cannot be changed. - %hash must have already been locked for this to have
useful effect. - lock_hash
unlock_hash - lock_hash(%hash);
- lock_hash() locks an entire hash, making all keys and
values readonly. No value can be changed, no keys can
be added or deleted.
unlock_hash(%hash);- unlock_hash() does the opposite of lock_hash(). All
keys and values are made read/write. All values can
be changed and keys can be added and deleted.
AUTHOR
Michael G Schwern <schwern@pobox.com> on top of code by
Nick Ing-Simmons and Jeffrey Friedl.
SEE ALSO
- Scalar::Util, List::Util, Hash::Util