polarbear has asked for the wisdom of the Perl Monks concerning the following question:
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.
Output:#!/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;
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];%services = ( 'service1' => { 'email' => [ 'worker@company.com', 'manager@company.com' ] }, 'service2' => { 'email' => $services{'service1'}{'email'} } );
|
---|
Back to
Seekers of Perl Wisdom