jaa has asked for the wisdom of the Perl Monks concerning the following question:
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
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Expanding / flattening a structure
by Fletch (Bishop) on Aug 24, 2006 at 18:29 UTC | |
|
Re: Expanding / flattening a structure
by ikegami (Patriarch) on Aug 24, 2006 at 18:52 UTC | |
|
Re: Expanding / flattening a structure
by holli (Abbot) on Aug 24, 2006 at 18:29 UTC | |
by jaa (Friar) on Aug 24, 2006 at 18:36 UTC | |
by jdtoronto (Prior) on Aug 24, 2006 at 18:44 UTC | |
by jaa (Friar) on Aug 24, 2006 at 19:16 UTC | |
by madbombX (Hermit) on Aug 24, 2006 at 18:44 UTC | |
by jaa (Friar) on Aug 24, 2006 at 19:23 UTC | |
|
Re: Expanding / flattening a structure
by planetscape (Chancellor) on Aug 25, 2006 at 01:05 UTC | |
|
Re: Expanding / flattening a structure
by bangers (Pilgrim) on Aug 25, 2006 at 14:28 UTC | |
by jaa (Friar) on Aug 25, 2006 at 15:08 UTC |