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