I have a compact structure like this:
I need to expand / flatten it out to this:# example structure my $struct = { fruit => [qw( apple pear )], type => [qw( organic farmed )], period => { 20050824 => { to => 'new york', to => 'london', }, 20050825 => { to => 'auckland', }, } };
I know that there is an elegant solution (recursive?) somewhere, but I am a bit stuck on how to approach it.# expanded into: my $expanded => [ { fruit => 'apple', type => 'farmed', period => 20050824, to => +'london' }, { fruit => 'apple', type => 'farmed', period => 20050824, to => +'new york' }, { fruit => 'apple', type => 'farmed', period => 20050825, to => +'auckland' }, { fruit => 'apple', type => 'organic', period => 20050824, to => +'london' }, { fruit => 'apple', type => 'organic', period => 20050824, to => +'new york' }, { fruit => 'apple', type => 'organic', period => 20050825, to => +'auckland' }, { fruit => 'pear', type => 'farmed', period => 20050824, to => +'london' }, { fruit => 'pear', type => 'farmed', period => 20050824, to => +'new york' }, { fruit => 'pear', type => 'farmed', period => 20050825, to => +'auckland' }, { fruit => 'pear', type => 'organic', period => 20050824, to => +'london' }, { fruit => 'pear', type => 'organic', period => 20050824, to => +'new york' }, { fruit => 'pear', type => 'organic', period => 20050825, to => +'auckland' }, ];
Any suggestions would be greatly appreciated.
Regards & thanks,
Jeff
In reply to Expanding / flattening a structure by jaa
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |