I don't understand what is going on in the following code. Service1 comes out as I expect with an array of email addresses. I expected Service2 to look the same but instead it gets a reference to service1 which is completely puzzling to me. I want to be able to add more addresses to the email lists individually for each service later on. I don't want the lists connected in any way.

#!/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 }, service2 => { email => \@maintainers }, ); print Data::Dumper->Dump( [ \%services ], [qw/*services/] ); exit 0;
Output:
%services = ( 'service1' => { 'email' => [ 'worker@company.com', 'manager@company.com' ] }, 'service2' => { 'email' => $services{'service1'}{'email'} } );
UPDATE: Thanks for all the replys, they did solve my problem though I am still puzzled as to why I got a reference to the hash value 'email' => $services{'service1'}{'email'} rather than a reference to say 'email' => $maintainers[0];

In reply to 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.