in reply to Array of dynamic Hash how to preserve the values

Core problem is too much indirection, which means you are making references back to an original when you probably intend to make copies. I won't dig too deep into this, but I'll show code that illustrates the problem.

This code just makes pointers to a single version of the structure, without making copies of the structure's changes.

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @data=({}); my %work_request = ( "DR"=>[0,0,0,0,0], "SAT ITAMS"=>[0,0,0,0,0], "PROD ITAMS"=>[0,0,0,0,0] ); #push @data, [ %work_request ]; push @data, \%work_request; $work_request{DR} = [1,2,3,4]; #push @data, [ %work_request ]; push @data, \%work_request; print Dumper( @data );
and the output is:

C:\Code>perl how_many_indirects.pl $VAR1 = {}; $VAR2 = { 'PROD ITAMS' => [ 0, 0, 0, 0, 0 ], 'SAT ITAMS' => [ 0, 0, 0, 0, 0 ], 'DR' => [ 1, 2, 3, 4 ] }; $VAR3 = $VAR2;


This version of code copies the unique components as the base structure changes.

#!/usr/bin/perl use warnings; use strict; use Data::Dumper; my @data=({}); my %work_request = ( "DR"=>[0,0,0,0,0], "SAT ITAMS"=>[0,0,0,0,0], "PROD ITAMS"=>[0,0,0,0,0] ); push @data, [ %work_request ]; #push @data, \%work_request; $work_request{DR} = [1,2,3,4]; push @data, [ %work_request ]; #push @data, \%work_request; print Dumper( @data );
and the output is:

C:\Code>perl how_many_indirects.pl $VAR1 = {}; $VAR2 = [ 'PROD ITAMS', [ 0, 0, 0, 0, 0 ], 'SAT ITAMS', [ 0, 0, 0, 0, 0 ], 'DR', [ 0, 0, 0, 0, 0 ] ]; $VAR3 = [ 'PROD ITAMS', $VAR2->[1], 'SAT ITAMS', $VAR2->[3], 'DR', [ 1, 2, 3, 4 ] ]; C:\Code>