in reply to Re^3: Attaching images to email html template help!
in thread Attaching images to email html template help!
I am curious about how I could fill the hashes dynamically
That largely depends on where you get the info from. Let's say you read a list of image paths from a file (__DATA__ here):
#!/usr/bin/perl -w use strict; my @imgs; while (my $path = <DATA>) { chomp $path; my ($fullname, $name, $ext) = $path =~ m#(([^/]+)\.(\w+))$#; my $type = "image/$ext"; $type =~ s/jpg$/jpeg/; push @imgs, { Type => $type, ID => $name, Path => $path, Filename => $fullname, Disposition => 'attachment', }; } use Data::Dumper; print Dumper \@imgs; __DATA__ /images/logo.gif /images/footer.gif /images/whatever.gif
produces:
$VAR1 = [ { 'ID' => 'logo', 'Disposition' => 'attachment', 'Type' => 'image/gif', 'Filename' => 'logo.gif', 'Path' => '/images/logo.gif' }, { 'ID' => 'footer', 'Disposition' => 'attachment', 'Type' => 'image/gif', 'Filename' => 'footer.gif', 'Path' => '/images/footer.gif' }, { 'ID' => 'whatever', 'Disposition' => 'attachment', 'Type' => 'image/jpeg', 'Filename' => 'whatever.jpg', 'Path' => '/images/whatever.jpg' } ];
|
|---|