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

In reply to Re: Putting an array into a hash gives an unexpected reference to the hash itself. by frozenwithjoy
in thread Putting an array into a hash gives an unexpected reference to the hash itself. by polarbear

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.