Hash::Work - Several static functions to manipulate hash-arrays
# exports all functions use Hash::Work ':all'; # E.g. a specific function use Hash::Work qw/merge_hashes/;
This class provides several static methods to manipulate hashes. Some of this methods you can also find in different modules, but I wanted to provide a simplier way to import that methods to a class.
Exporter
Clone
Hash::Merge
5.006
my \%hashref = array_to_hash(@array | \@arrayref);
Converts simply an array to a hash by using the array entries as key and a 1 as value. Returns context specific a reference to a hash or a hash.
copy_hash_values(\%from, \%to);
copy the hash values from first hash to the second.
my \%hashref = first_arrays_to_hash(\%hashref);
removes arrays from a hash recursively by taking first array entry.
example:
input:
$VAR1 = { 'anode' => [ { 'name' => 'anything', 'abc' => [ { 'foo' => [ 'text' ] } ] } ] };
output:
$VAR1 = { 'anode' => { 'name' => 'anything', 'abc' => { 'foo' => 'text' } } };
I use it to handle some results of XML::Simple, to flaten it.
my \%hashref = merge_hashes(\%hashref1, \%hashref2);
takes 2 hashes and merges them by using their keys to one hash. returns a hash or hashref, depending on the context call. It uses the Hash::Merge class.
The second entry weights more then the second and overwrites the first values.
my $h1 = { 'def' => '456', 'foo' => 'ooo', }; my $h2 = { 'def' => '777', 'more' => 'mmm', }; my $res = merge_hashes($h1,$h2);
$res has then:
$VAR1 = { 'def' => '777', 'foo' => 'ooo', 'more' => 'mmm' };
Returns a hash or hashref. depending onthe context
Andreas Hernitscheck ahernit(AT)cpan.org
You can redistribute it and/or modify it under the conditions of LGPL.
To install Hash::Work, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Hash::Work
CPAN shell
perl -MCPAN -e shell install Hash::Work
For more information on module installation, please visit the detailed CPAN module installation guide.