Hash::Work - Several static functions to manipulate hash-arrays


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

Exporter

Clone

the Hash::Merge manpage

5.006


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

 first_arrays_to_hash();

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

 merge_hashes();

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.


AUTHOR

Andreas Hernitscheck ahernit(AT)cpan.org


LICENSE

You can redistribute it and/or modify it under the conditions of LGPL.

 Hash::Work - Several static functions to manipulate hash-arrays