Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

Re: How to flatten hashes?

by dirac (Beadle)
on Jul 14, 2005 at 08:03 UTC ( #474789=note: print w/replies, xml ) Need Help??


in reply to How to flatten hashes?

#!/usr/bin/perl -w use strict; use Data::Dumper; my %a = ('accesslevels' => { 'function' => { 'func1' => { 'content' => 'val1' }, 'default' => { 'content' => 'val2' } } } ); my %b = map { $_, { func1 => $a{$_}{function}{func1}{content} , default => $a{$_}{function}{default}{content} } } keys %a; print Dumper(%a); print Dumper(%b);
Update:
This works for generic hash with the same structure.
Try with ...
my %a = ('accesslevels' => { 'function' => { 'func1' => { 'content' => 'val1' }, 'default' => { 'content' => 'val2' } } } , 'accesslevels1' => { 'function' => { 'func1' => { 'content' => 'val3' }, 'default' => { 'content' => 'val4' } } } , 'accesslevels2' => { 'function' => { 'func1' => { 'content' => 'val5' }, 'default' => { 'content' => 'val6' } } } , 'accesslevels3' => { 'function' => { 'func1' => { 'content' => 'val7' }, 'default' => { 'content' => 'val8' } } } , 'accesslevels4' => { 'function' => { 'func1' => { 'content' => 'val9' }, 'default' => { 'content' => 'val10' } } } , );

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others lurking in the Monastery: (2)
As of 2023-05-28 06:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?