Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

Re: How to flatten hashes?

by duelafn (Vicar)
on Jul 14, 2005 at 12:01 UTC ( #474839=note: print w/replies, xml ) Need Help??


in reply to How to flatten hashes?

Not sure this qualifies as more elegant, or just more obfuscated than rev_1318's solution.

use YAML; my %h = ( 'accesslevels' => { 'function' => { 'func1' => { 'content' => 'val1' }, 'default' => { 'content' => 'val2' } } }, 'accesslevels2' => { 'function' => { 'func1' => { 'content' => 'val1' }, 'default' => { 'content' => 'val2' } } }); for my $L (values %h) { my (%tmp, $k, $v); for (values %$L) { $tmp{$k} = $$v{content} while ($k,$v) = each %$_; } $L = \%tmp; } print Dump \%h;

Good Day,
    Dean

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others chilling in the Monastery: (6)
As of 2019-08-23 15:59 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?