http://qs1969.pair.com?node_id=474789


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' } } } , );