http://qs321.pair.com?node_id=1165232


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:
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 } );
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.