I am using Mail::Sender to send an email message and have used it a few times before but have hard coded the email address into the script. Now I am using Config::ApacheFormat (which I have also used before) for a config file. I know how to get an email address from the config file and use it in the code. However, I have a place where I am using an eval block to send an email. I have to assume (since I don't know better) that the email address is being interpolated. I think the way I want to fix it is to make that variable not be eval'd inside of the eval block. The corresponding lines in the config file are:
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")),

In reply to Unevaling part of an eval block by madbombX

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.