I'm currently working on a script that basically needs to read data from one of our databases, do some fairly basic processing on it, and then output that data to a file for reporting.
The data is returned from the database in an AOH, where each hash of the array corresponds to a row returned from the table.
Once this data has been read, the script takes each hash in turn, reads the customer ID, and finds the list of open orders for that customer. It then attempts to create a copy of the original hash for each order id, and pushes each new hash onto an output array.
The problem seems to occur with the push. If I output the data hash-by-hash just prior to the push, I get perfect data, but if I dump out the final array once the loop is complete, I seem to get very corrupt data - a whole load of undef and references to $output->[1].
The loop I'm using to modify the data and push onto the new array is as follows:
I've been trying to figure this out for ages, and I've not had any luck - I'm wondering if I have referencing problems, but I've tried modifying the push with no luck as yet.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; print Dumper $hash; # outputting here yields perfect data push @$output, $hash; } } print Dumper $output; # outputting here gives trashed data
Can anyone see where this is going wrong? Any suggestions at this point would be appreciated :)
Thanks in advance,
-- Foxcub
A friend is someone who can see straight through you, yet still enjoy the view. (Anon)
In reply to Push corrupting data by Tanalis
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |