Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: How to flatten hashes?

by tlm (Prior)
on Jul 14, 2005 at 13:13 UTC ( [id://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

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (5)
As of 2024-03-29 01:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found