Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: How to flatten hashes?

by tlm (Prior)
on Jul 14, 2005 at 13:13 UTC ( #474859=note: print w/ replies, xml ) Need Help??


in reply to How to flatten hashes?

FWIW,

use strict; use warnings; my %hash = ( accesslevels => { function => { func1 => { content => 'val1 +' }, default => { content => 'val2 +' } } } ); sub flatten { my $hash = shift; while ( my ( $k, $v ) = each %$hash ) { next unless ref $v eq 'HASH'; flatten( $v ); exists $v->{ $_ } and $hash->{ $k } = $v->{ $_ } for qw( function content ) } } use Dumpvalue; flatten( \%hash ); print Dumpvalue->new->dumpValue( \%hash ); __END__ 'accesslevels' => HASH(0x814cad4) 'default' => 'val2' 'func1' => 'val1'

the lowliest monk


Comment on Re: How to flatten hashes?
Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://474859]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others musing on the Monastery: (5)
As of 2014-07-26 03:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (175 votes), past polls