The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

NAME

Tie::Hash::FixedKeys - Perl extension for hashes with fixed keys

SYNOPSIS

  use Tie::Hash::FixedKeys;

  my @keys = qw(forename surname 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

or (new! improved!)

  use Tie::Hash::FixedKeys;

  my %person : FixedKeys(qw(forename surname date_of_birth gender));

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.

ATTRIBUTE INTERFACE

From version 1.5, you can use attributes to set the keys for your hash. You will need Attribute::Handlers version 0.76 or greater.

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