in reply to Re: Strange hash array behavior
in thread Strange hash array behavior
Which of course produces the same result just as you explain. But after messing with this I am not able to make it do what I want.use strict; use warnings; use Data::Dumper; my $data1 = [ { "shape" => "round", "food" => "apple" }, { "shape" => "square", "food" => "pear" } ]; my $data2 = [ { "big" => "cow", "small" => "bunny" }, ]; my $combined; foreach my $r (@{$data1}) { $r->{sizes} = $data2; push(@{$combined},$r); } print Dumper($combined);
I suppose it is because I am not really grasping it totally, which bothers me because I thought I had references down.
Can you modify the code above to produce the result I am looking for... do you see what I am trying to do? $data2 needs to reside outside that loop and I am wanting this result:
Thanks! Thanks!$VAR1 = [ { 'food' => 'apple', 'shape' => 'round', 'sizes' => [ { 'small' => 'bunny', 'big' => 'cow' } ] }, { 'food' => 'pear', 'shape' => 'square', 'sizes' => [ { 'small' => 'bunny', 'big' => 'cow' } ] } ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^3: Strange hash array behavior
by Util (Priest) on Jan 29, 2009 at 05:02 UTC | |
by Rodster001 (Pilgrim) on Jan 29, 2009 at 05:19 UTC | |
by ikegami (Patriarch) on Jan 29, 2009 at 15:26 UTC | |
by ig (Vicar) on Jan 29, 2009 at 05:53 UTC | |
by Rodster001 (Pilgrim) on Jan 29, 2009 at 06:14 UTC | |
by Util (Priest) on Jan 29, 2009 at 07:35 UTC | |
| |
by Util (Priest) on Jan 29, 2009 at 06:27 UTC |