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.
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.#!/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' ] } );
In reply to Re: Putting an array into a hash gives an unexpected reference to the hash itself.
by Perlbotics
in thread Putting an array into a hash gives an unexpected reference to the hash itself.
by polarbear
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |