http://www.perlmonks.org?node_id=1002769


in reply to Putting an array into a hash gives an unexpected reference to the hash itself.

Sure, they are the same. You assigned the same reference twice.

If you want two different copies, use two different references. E.g. the original \@maintainers and a copy [ @maintainers ] or two new copies.

#!/usr/local/bin/perl -w use strict; use warnings; use Data::Dumper; my @maintainers = qw/ worker@company.com manager@company.com /; my %services = ( service1 => { email => [ @maintainers ] }, # shallow copy of @main +tainers service2 => { email => [ @maintainers ] }, # another shallow ... ); print Data::Dumper->Dump( [ \%services ], [qw/*services/] ); exit 0; __DATA__ %services = ( 'service1' => { 'email' => [ 'worker@company.com', 'manager@company.com' ] }, 'service2' => { 'email' => [ 'worker@company.com', 'manager@company.com' ] } );

One more thing. I was creating a shallow copy in the example above. For more complex data structures, you might need to copy recursively or use something like Storable::dclone or Clone.