NAME
Hash::Work - Several static functions to manipulate hash-arrays
SYNOPSIS
# exports all functions
use Hash::Work ':all';
# E.g. a specific function
use Hash::Work qw/merge_hashes/;
DESCRIPTION
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.
REQUIRES
METHODS
array_to_hash
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
copy_hash_values(\%from, \%to);
copy the hash values from first hash to the second.
first_arrays_to_hash
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.
merge_hashes
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
AUTHOR
Andreas Hernitscheck ahernit(AT)cpan.org
LICENSE
You can redistribute it and/or modify it under the conditions of LGPL.