in reply to Push corrupting data
you're pushing the same hash on the list, i think you want to make a copy yes?
my $data = [ { cust_id => 1 }, { cust_id => 3 }, ]; my $order_data = { 1 => { order_ids => '5,6' }, 3 => { order_ids => '7,8,9' }, }; my $output = []; foreach my $hash (@$data) { my $cust_id = $hash->{cust_id}; foreach my $id (split ',', $order_data->{$cust_id}->{order_ids}) { $hash->{order_id} = $id; push @$output, {%{$hash}}; } } use Data::Dumper; print Dumper $output; __END__ $VAR1 = [ { 'cust_id' => 1, 'order_id' => '5' }, { 'cust_id' => 1, 'order_id' => '6' }, { 'cust_id' => 3, 'order_id' => '7' }, { 'cust_id' => 3, 'order_id' => '8' }, { 'cust_id' => 3, 'order_id' => '9' } ];
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Push corrupting data
by Tanalis (Curate) on Mar 13, 2003 at 09:25 UTC | |
by robartes (Priest) on Mar 13, 2003 at 09:44 UTC |