NAME
Tie::Hash::FixedKeys - Perl extension for hashes with fixed keys
SYNOPSIS
use Tie::Hash::FixedKeys;
my @keys = qw(forename surename date_of_birth gender);
my %person;
tie %person, 'Tie;::Hash::FixedKeys', @keys;
@person{@keys} = qw(Fred Bloggs 19700101 M);
$person{height} = "6'"; # generates a warning
DESCRIPTION
Tie::Hash::FixedKeys is a class which changes the behaviour of Perl hashes. Any hash which is tied to this class can only contain a fixed set of keys. This set of keys is given when the hash is tied. For example, after running the code:
my @keys = qw(forename surename date_of_birth gender);
my %person;
tie %person, 'Tie;::Hash::FixedKeys', @keys;
the hash %person
can only contain the keys forename, surname, date_of_birth and gender. Any attempt to set a value for another key will generate a run-time warning.
CAVEAT
The tied hash will always contain exactly one value for each of the keys in the list. These values are initialised to undef
when the hash is tied. If you try to delete
one if the keys, the effect is that the value is reset to undef
.
AUTHOR
Dave Cross <dave@dave.org.uk>
SEE ALSO
perl(1), perltie(1).