in reply to Re: Attaching images to email html template help!
in thread Attaching images to email html template help!

Thanks for your response, it was a great help.
If I change my sub routine "email" from my sample code here into a module and lets say I would be passing all the values to this new module now called mod_email like this;
mod_email( {to=>$to, from => $email, subject=>$subject, body=>$body, ttparams => $templ_data} );
There is no problem passing the values into the module like that, but how could I pass this array of hashes "@imgs" to this module? Here is some lines of code of my trying for your opinion:
#from the .pl file call the module ... mod_email( {to=>$to, from => $email, subject=>$subject, body=>$body, t +tparams => $templ_data},imgs=>@imgs ); #now this part would be code inside of the module mod_email ... sub process_email_stuff { my ($vals) = @_; my $to = $vals->{ to } || {}; my $from = $vals->{ from } || {}; my $subject = $vals->{ subject } || {}; my $body = $vals->{ body } || {}; my $ttparams = $vals->{ ttparams } || {}; #questioning this: my @imgs = $vals->{ imgs } || {}; my $msg = MIME::Lite::TT::HTML->new( From => $from, ... #all the other stuff its done, now get to the @imgs processing, hopefu +lly. for my $img (@imgs ) { $msg->attach( %$img ) or die "Error adding $img- {Filename}: $!\n" +; } ... 1;

I hope this is clear about want I am trying to accomplish, and thanks once again!

Replies are listed 'Best First'.
Re^3: Attaching images to email html template help!
by Eliya (Vicar) on Mar 18, 2011 at 13:54 UTC
    how could I pass this array of hashes "@imgs" to this module?

    Normally, you'd pass a reference to it, i.e. \@imgs

    email( {to=>$to, from => $email, ..., imgs => \@imgs} ); ... sub email { my ($vals) = @_; ... my $imgs = $vals->{ imgs } || []; ...

    Further on, you then just dereference it the usual way: @$imgs for the entire array, or $imgs->[0] for a single element (which would be a hashref in your particular case).

    See also perlreftut and perlref.

    P.S. you probably don't want to supply an empty hashref ({}) as defaults for things which are normally just scalars/strings, such as your

    my $to = $vals->{ to } || {}; my $from = $vals->{ from } || {}; my $subject = $vals->{ subject } || {}; ...