in reply to Re^2: Replace a value with another value from the same array
in thread Replace a value with another value from the same array
Ok, here's a solution that does it on a single pass regardless of order, it takes advantage of the fact that the array elements are references to the anonymous hashes (perlreftut, perlref, perldsc):
my ($source,$target); for my $item (@$all) { if ( $item->{code} eq 'XXY' ) { $source = $item; $target->{expdate} = $item->{expdate} if defined $target; } if ( $item->{code} eq 'YYK' ) { $target = $item; $item->{expdate} = $source->{expdate} if defined $source; } }
|
|---|