I have a HoAoH as in the following distilled example:
use strict; use warnings; use Data::Dumper; my %types = ( TYPE1 => [ { NAME => 'Joe', ID => '022'}, { NAME => 'Sue', ID => '088'}, { NAME => 'Tom', ID => '108'} ], TYPE2 => [ { NAME => 'Sue_B', ID => '089'}, { NAME => 'Sue_C', ID => '090'} ] ); splice @{$types{TYPE1}}, 1, 1, @{$types{TYPE2}}; print Dumper(\%types)
I am trying to replace the 'Sue' hash element in the array referenced by TYPE1 with both of the hash elements in the array referenced by TYPE2.
It seems to me that the splice should do the trick, but doesn't, producing the following output instead:
$VAR1 = { 'TYPE2' => [ { 'ID' => '089', 'NAME' => 'Sue_B' }, { 'ID' => '090', 'NAME' => 'Sue_C' } ], 'TYPE1' => [ { 'ID' => '022', 'NAME' => 'Joe' }, $VAR1->{'TYPE2'}[0], $VAR1->{'TYPE2'}[1], { 'ID' => '108', 'NAME' => 'Tom' } ] };
I am attempting to splice because I want to preserve the order of the elements in the arrays. Can anyone clue me in to what I am doing wrong and what a proper way of doing this would be?
In reply to Slicing a HoAoH by Art_XIV
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |