Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
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
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 studying the Monastery: (7)
As of 2019-08-23 15:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?