jaydstein has asked for the wisdom of the Perl Monks concerning the following question:
I'm still getting acquainted with perl datastructures. I have a working structure for storing my data... but it is UGLY and BULKY. I'm sure there is a better way to do this... someone please slap me across the face and show me the error of my ways.
Note... the order in which the data is accessed is important! It is also my preference to preserve the key-value relationship between the data if at all possible.
my @fooFeatures = ( { 'Baked Goods' => [ { 'Cookies' => ['Chocolate Chip', 'Oreo'] }, ]}, { 'Fruits' => [ { 'Apples' => ['Fuji', 'Granny Smith'] }, { 'Oranges' => ['Tangerine', 'Navel'] }, ]}, ); for my $fooSet ( @fooFeatures ) { while (my ($key, $value) = each(%$fooSet)) { for my $hash ( @{$value} ) { while (my ($k, $v) = each(%$hash)) { for my $feature ( @{$v} ) { print "($k, $feature)<br>"; } } } } }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: AoHoAoH... am I delusional?
by NetWallah (Canon) on Feb 08, 2012 at 04:45 UTC | |
|
Re: AoHoAoH... am I delusional?
by planetscape (Chancellor) on Feb 08, 2012 at 01:36 UTC | |
|
Re: AoHoAoH... am I delusional?
by VinsWorldcom (Prior) on Feb 08, 2012 at 02:05 UTC | |
|
Re: AoHoAoH... am I delusional?
by BrowserUk (Patriarch) on Feb 08, 2012 at 01:20 UTC | |
|
Re: AoHoAoH... am I delusional?
by tobyink (Canon) on Feb 08, 2012 at 06:54 UTC | |
by jhourcle (Prior) on Feb 08, 2012 at 20:06 UTC | |
|
Re: AoHoAoH... am I delusional?
by lutok (Scribe) on Feb 08, 2012 at 18:18 UTC |