I guess what you really want is to merge two hash refs. Corion wrote this 11 years ago. You might try something like this:
#!/usr/bin/env perl use strict; use warnings; use Hash::Merge qw(merge); use Data::Dump; use Test::More tests => 1; my $data_a = { 'fullname' => 'Ms Mary Lou', 'first' => 'Mary', 'last' => 'Lou', }; my $data_b = { 'house' => 'main', 'number' => '0123', 'area' => 'north', 'code' => 'zip', }; my $expected = { 'house' => 'main', 'number' => '0123', 'area' => 'north', 'code' => 'zip', 'fullname' => 'Ms Mary Lou', 'first' => 'Mary', 'last' => 'Lou', }; dd $data_a; dd $data_b; dd $expected; my $result = merge( $data_a, $data_b ); dd $result; is_deeply( $result, $expected, qq(merged hash refs) ); __END__ Karls-Mac-mini:Desktop karl$ ./merge.pl 1..1 { first => "Mary", fullname => "Ms Mary Lou", last => "Lou" } { area => "north", code => "zip", house => "main", number => "0123" } { area => "north", code => "zip", first => "Mary", fullname => "Ms Mary Lou", house => "main", last => "Lou", number => "0123", } { area => "north", code => "zip", first => "Mary", fullname => "Ms Mary Lou", house => "main", last => "Lou", number => "0123", } ok 1 - merged hash refs
Please see also Hash::Merge, Test::More and Data::Dump. A look at ref might be probably useful as well. Best regards, Karl
«The Crux of the Biscuit is the Apostrophe»
perl -MCrypt::CBC -E 'say Crypt::CBC->new(-key=>'kgb',-cipher=>"Blowfish")->decrypt_hex($ENV{KARL});'Help
In reply to Re: Add array ref to another array ref
by karlgoethebier
in thread Add array ref to another array ref
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |