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

The problem is that you are creating two references to the same thing and want them to be distinct, but they aren't (because they reference the same thing...).

Instead of this:

my %services = ( service1 => { email => \@maintainers }, service2 => { email => \@maintainers }, );

You probably want this:

my %services = ( service1 => { email => [ @maintainers ] }, service2 => { email => [ @maintainers ] }, );

Below is an example showing what can happen when using/altering references. I make two references to a single scalar, alter one of the references and show that the contents of the original scalar and both references to that scalar change (but not a copy of the original).

#!/usr/bin/env perl use strict; use warnings; use feature 'say'; my $a = "original"; my $a_ref1 = \$a; my $a_ref2 = \$a; my $a_copy = $a; say "\$a is $a"; say "\$a_ref1 is $$a_ref1"; say "\$a_ref2 is $$a_ref2"; say "\$a_copy is $a_copy"; say "OK, let's alter only the first reference (\$a_ref1):"; $$a_ref1 = "altered"; say "\$a is $a"; say "\$a_ref1 is $$a_ref1"; say "\$a_ref2 is $$a_ref2"; say "\$a_copy is $a_copy";

Output:

$a is original $a_ref1 is original $a_ref2 is original $a_copy is original OK, let's alter the first reference ($a_ref1): $a is altered $a_ref1 is altered $a_ref2 is altered $a_copy is original

Replies are listed 'Best First'.
Re^2: Putting an array into a hash gives an unexpected reference to the hash itself.
by polarbear (Novice) on Nov 08, 2012 at 01:00 UTC
    Thank you, that solved my problem.