Name : perl-Tie-ListKeyedHash
| |
Version : 1.03
| Vendor : obs://build_opensuse_org/devel:languages:perl
|
Release : lp155.1.1
| Date : 2023-07-20 19:31:43
|
Group : Development/Libraries/Perl
| Source RPM : perl-Tie-ListKeyedHash-1.03-lp155.1.1.src.rpm
|
Size : 0.03 MB
| |
Packager : https://www_suse_com/
| |
Summary : System allowing the use of anonymous arrays as keys to a hash
|
Description :
Tie::ListKeyedHash ties a hash so that you can use a reference to an array as the key of the hash. It otherwise behaves exactly like a normal hash (including all caveats about trying to use a key as both a hash reference and a scalar value).
This frees you from needing to \'hardwire\' hash references in code or having to write tree traversal code to reach arbitrary points in a hash tree.
Example:
use strict; use warnings;
use Data::Dumper;
use Tie::ListKeyedHash;
my %example; tie (%example, \'Tie::ListKeyedHash\');
%example = ( \'a\' => { \'b0\' => { \'c\' => \'value of c\', \'d\' => \'value of d\', \'e\' => { \'f\' => \'value of f\', }, }, \'b1\' => { \'g\' => \'value of g\', }, }, \'h\' => \'r\', );
my $b_key = [\'a\',\'b0\'];
my $d_key = [AATT$b_key,\'d\']; my $d = $example{$d_key}; print \"d = $d\ \";
my $e_key = [AATT$b_key, \'e\']; my $e = $example{$e_key}; print \'e = \' . Dumper ($e);
my $f_key = [AATT$b_key, \'e\',\'f\']; my $f = $example{$f_key}; print \"f = $f\ \";
my $h_key = [\'h\']; my $h = $example{$h_key}; print \"h = $h\ \";
The virtues of this particular way of accessing hash-of-hashes (HoH) vs bare hardwired derefererences or \'tree crawling\' are as follows:
1) As the number of levels in a HoH increases, the tied object asymptotically approaches the speed of hardwired hash dereferencing without the loss of flexibility penalty of having to hardwire the keys into code in advance.
This gives an important property that it _gets faster_ the deeper a HoH becomes as compared with the speed of software driven tree traveral.
So you can build and access arbitrarily structured HoH and still access deeply buried elements in the tree _quickly_.
2) The format was designed to use memory efficiently. It takes only a few hundred extra bytes over the size of an untied HoH in memory or when serialized (via Data::Dumper or Storable for example) regardless of how deep the hash is.
3) A reference to an existing HoH can be passed into Tie::ListKeyedHash->new and all of the OO key lists access methods will *\"just work\"*.
Example:
use Tie::ListKeyedHash;
my %hash = ( \'a\' => { \'b\' => \'c\' } ); my $obj = Tie::ListKeyedHash->new(\\%hash);
my $b_value = $obj->get([\'a\',\'b\']);
|
RPM found in directory: /packages/linux-pbone/ftp5.gwdg.de/pub/opensuse/repositories/devel:/languages:/perl:/CPAN-T/15.5/noarch |