Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: How to flatten hashes?

by rev_1318 (Chaplain)
on Jul 14, 2005 at 08:09 UTC ( [id://474792]=note: print w/replies, xml ) Need Help??


in reply to How to flatten hashes?

If your hash is all you show us, you can simply say:
my %newhash = ( accesslevels => { func1 => $oldhash{function}{func1}{content}, default => $oldhash{function}{default}{content} } );
But if it is more generic (which I'm guessing it is), a possible approach can be:
my %newhash; foreach my $key1 (keys %oldhash) { foreach my $key2 (keys %{$oldhash{$key1}}) { foreach my $key3 (keys %{$oldhash{$key1}{$key2}}) { $newhash{$key1}{$key3} = $oldhash{$key1}{$key2}{$key3}{con +tent} } } }
HTH

Paul

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://474792]
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-04-25 14:40 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found