madbombX has asked for the wisdom of the Perl Monks concerning the following question:
AdminEmail "Server Admin" <admin@server.com> AdminEmailCC "Tech Guys" <techs@server.com>
The corresponding code is (I know I am using 2 different methods to get the config lines, but I am just doing that to illustrate the flexibility I have with the code):
my $to = join(" ", $config->get("AdminEmail")); eval { (new Mail::Sender)->MailMsg( { smtp => "mail.server.com", from => "\"Postmaster\" <postmaster\@server.com>", to => $to, cc => $config->get("AdminEmailCC"), subject => "Email Subject", msg => "Email Body" }) or die "Error Sending Mail: $Mail::Sender::Error"; };
And the corresponding error message is: Odd number of elements in anonymous hash at my_script.pl line 454.
Can someone please explain to me what is happening here and how I can fix it?
Update: Thanks to merlyn and chromatic for setting me straight. It appears that in an eval block, the string is being called into an anonymous hash with an odd nuber of elements since the method is being called in a list context. The corrected section of code forces the string into a scalar context:
to => scalar join(" ", $config->get("AdminEmail")), cc => scalar join(" ", $config->get("AdminEmailCC")),
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Unevaling part of an eval block
by merlyn (Sage) on Nov 26, 2006 at 04:53 UTC | |
|
Re: Unevaling part of an eval block
by chromatic (Archbishop) on Nov 26, 2006 at 06:59 UTC | |
|
Re: Unevaling part of an eval block
by roboticus (Chancellor) on Nov 26, 2006 at 13:50 UTC |