in reply to Re: Expanding / flattening a structure
in thread Expanding / flattening a structure

Apologies, you are right, here is a better example of the input:
my $struct = { fruit => [qw( apple pear )], type => [qw( farmed organic )], period => { 20050824 => { to => ['new york', 'london', ], }, 20050825 => { to => ['auckland', ], }, } };
update: fixed first date [ -> {

Replies are listed 'Best First'.
Re^3: Expanding / flattening a structure
by jdtoronto (Prior) on Aug 24, 2006 at 18:44 UTC
    Maybe:
    # example structure my $struct = { fruit => [qw( apple pear )], type => [qw( farmed organic )], period => { 20050824 => [ to => ['new york', 'london' ], ], 20050825 => [ to => ['auckland' ], ], }, };
    Would be syntactically valid?

    But given the only attribute to the date is to, why not remove that layer?

    jdtoronto

      two reasons for the 'to':

      1) the token 'to' names the values in the result,

      e.g. I end up with this in the expanded array of hashes:

      to => 'auckland',

      2) also, this is just an example, in reality there are more values, e.g.

      period => { 20050824 => { to => [ 'auckland', 'new york', ], transport => [ 'air', ] }, },
Re^3: Expanding / flattening a structure
by madbombX (Hermit) on Aug 24, 2006 at 18:44 UTC
      I think that $struct is already reasonable efficient? Did you have a recommendation for a better way to structure it?