Tie::Subset::Hash - Tie a hash to a subset of another hash
use Tie::Subset::Hash; my %hash = ( foo=>11, bar=>22, quz=>33 ); tie my %subset, 'Tie::Subset::Hash', \%hash, ['bar','quz']; print "$subset{bar}\n"; # prints "22" $subset{quz}++; # modifies $hash{quz}
This class for tied hashes provides a "view" of a subset of a hash.
tie
tie my %subset, 'Tie::Subset::Hash', \%hash, \@keys;
You must specify which subset of keys from the original hash can be accessed via the tied hash. (Keys that do not yet exist in the original hash may be specified.)
If the key is in the subset, the value from the underlying hash is returned, otherwise returns nothing (undef).
If the key is in the subset, the new value will be stored in the underlying hash, otherwise the operation is ignored and a warning issued.
exists
Will return true only if the key is in the subset and it exists in the underlying hash.
each
keys
Only keys that exist are both in the subset and the underlying hash are iterated over.
delete
If the key is in the subset, the key will be deleted from the underlying hash, but not the subset. Otherwise, the operation is ignored and a warning issued.
Not (yet) supported (because it is ambiguous whether this operation should delete keys from the underlying hash or not). Attempting to clear the tied hash currently does nothing and causes a warning to be issued.
A future version of this module may lift this limitation (if a useful default behavior exists).
"See Also" in Tie::Subset
Copyright (c) 2018 Hauke Daempfling (haukex@zero-g.net).
This library is free software; you can redistribute it and/or modify it under the same terms as Perl 5 itself.
For more information see the Perl Artistic License, which should have been distributed with your copy of Perl. Try the command perldoc perlartistic or see http://perldoc.perl.org/perlartistic.html.
perldoc perlartistic
To install Tie::Subset, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Tie::Subset
CPAN shell
perl -MCPAN -e shell install Tie::Subset
For more information on module installation, please visit the detailed CPAN module installation guide.