NAME

Tie::UnionHash - Union hashes. Make changes to the last hash in arguments ( depend on option <freeze_keys>).

SYNOPSIS

use Tie::UnionHash;
 
tie %uhash, 'Tie::UnionHash', \%hash1ro, \%hash2rw;

tie %hashu, 'Tie::UnionHash', \%hash1, \%hash2, 'freeze_keys' ;

DESCRIPTION

Tie::UnionHash - Merge multiple hashes into a one hash. Make changes only to the last hash in arguments, unless used option freeze_keys.

Tie::UnionHash can handle anything that looks like a hash; just give it a reference as one of the additional arguments to tie(). This includes other tied hashes, so you can include DB and DBM files as data sources for a union hash. If given a plain name instead of a reference, it will use as option.

UnionHash correctly distinguish deleted keys.

my %hash1 = ( 1 => 1, 3 => 3 );
my %hash2 = ( 2 => 2, 3 => 3 );
my %hashu;
tie %hashu, 'Tie::UnionHash', \%hash1, \%hash2;
# keys %hashu  is [ '1', '2', '3' ]
$hashu{3} = 4 #change %hash2;
delete $hashu{3} #change %hash2 and track deleted keys
exist $hashu{3} # false, but exists in read only hashes

Option freeze_keys will change mode to readonly keys in hashes, except last hash in arguments.

   my %hash1 = ( 1 => 1, 3 => 3 );
   my %hash2 = ( 2 => 2, 3 => 3 );
   my %hashu;
   tie %hashu, 'Tie::UnionHash', \%hash1, \%hash2, 'freeze_keys' ;
   $hashu{3} = 4 #make changes to   %hash1 :  ( 1 => 1, 3 => 4 );
   $hashu{NEW_KEY} = 1 # make changes to   %hash2 :
                       #( 2 => 2, 3 => 3,  NEW_KEY =>1 );;

SEE ALSO

Tie::StdHash

AUTHOR

Zahatski Aliaksandr, <zag@cpan.org>

COPYRIGHT AND LICENSE

Copyright (C) 2005-2007 by Zahatski Aliaksandr

This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself, either Perl version 5.8.8 or, at your option, any later version of Perl 5 you may have available.