Hash::Flatten

Flatten/unflatten complex data hashes
Download

Hash::Flatten Ranking & Summary

Advertisement

  • Rating:
  • License:
  • GPL
  • Price:
  • FREE
  • Publisher Name:
  • BBC
  • Publisher web site:
  • http://www.bbc.co.uk

Hash::Flatten Tags


Hash::Flatten Description

Flatten/unflatten complex data hashes Hash::Flatten is a Perl module that converts back and forth between a nested hash structure and a flat hash of delimited key-value pairs. Useful for protocols that only support key-value pairs (such as CGI and DBMs).Functional interface$flat_hash = flatten($nested_hash, \%options) Reduces a nested data-structure to key-value form. The top-level container must be hashref. For example: $nested = { 'x' => 1, 'y' => { 'a' => 2, 'b' => 3 }, 'z' => } $flat = flatten($nested); use Data::Dumper; print Dumper($flat); $VAR1 = { 'y.a' => 2, 'x' => 1, 'y.b' => 3, 'z:0' => 'a', 'z:1' => 'b', 'z:2' => 'c' };The \%options hashref can be used to override the default behaviour (see "OPTIONS").$nested_hash = unflatten($flat_hash, \%options)The unflatten() routine takes the flattened hash and returns the original nested hash (see "CAVEATS" though).OO interface$o = new Hash::Flatten(\%options)Options can be squirreled away in an object (see "OPTIONS")$flat = $o->flatten($nested)Flatten the structure using the options stored in the object.$nested = $o->unflatten($flat)Unflatten the structure using the options stored in the object.SYNOPSIS # Exported functions use Hash::Flatten qw(:all); $flat_hash = flatten($nested_hash); $nested_hash = unflatten($flat_hash); # OO interface my $o = new Hash::Flatten({ HashDelimiter => '->', ArrayDelimiter => '=>', OnRefScalar => 'warn', }); $flat_hash = $o->flatten($nested_hash); $nested_hash = $o->unflatten($flat_hash); Requirements: · Perl


Hash::Flatten Related Software