in reply to Odd number of elements in anonymous hash
$attached is a hash reference so you need to dereference it, and default to an empty hash ref if $code is false:
Update: as pryrt points out, $attached is not a hash reference (it is a string) but can easily be made into one - see my further example below.my $attached = ($code) ? "attach_path => '$file_name',attach_filena +m +e => '$file_name',attach_type => 'application/txt'," : {}; my $success = email( { to => $email, from => $from, from_name => $name, subject => $subject, body => $body, %$attached } );
|
---|
Replies are listed 'Best First'. | |
---|---|
Re^2: Odd number of elements in anonymous hash
by pryrt (Abbot) on Jun 09, 2016 at 16:15 UTC | |
by Athanasius (Archbishop) on Jun 09, 2016 at 16:23 UTC | |
by tangent (Parson) on Jun 09, 2016 at 16:24 UTC | |
by Anonymous Monk on Jun 09, 2016 at 17:23 UTC | |
Re^2: Odd number of elements in anonymous hash
by BillKSmith (Monsignor) on Jun 09, 2016 at 18:19 UTC |
In Section
Seekers of Perl Wisdom