Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: How to flatten hashes?

by duelafn (Parson)
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
Domain Nodelet?
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 meditating upon the Monastery: (2)
As of 2023-06-11 01:24 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    How often do you go to conferences?






    Results (40 votes). Check out past polls.

    Notices?