It's a good idea to separate the output from the logic if you can, especially if that output is HTML. Consider this:
use Modern::Perl; use Email::Send::SMTP::Gmail; use POSIX qw(strftime); use File::Find::Rule; use Template; my $subject = "ICS -- Files in the Error Folder"; my $email = 'bflieck@xxx.com'; my @bad_files = File::Find::Rule ->file() ->relative ->maxdepth( 1 ) ->name( '*.jpg', '*.tif', '*.tiff', '*.psd' ) ->in( '/Volumes/photorepos/Partners/WorkHorse/ERROR/PhotographyDro +p_ERROR' ); # Group files per user my %bad_files_per_user; foreach my $file ( @bad_files ) { my $user = (split /-/, $file)[0]; $bad_files_per_user{ $user } = $file; } # Prepare the email text my $body = Template->new->process( \*DATA, { subject => $subject, files => \%bad_files_per_user, date => strftime( "%m-%d-%y", localtime ), time => strftime( "%I:%M:%S", localtime ), }); # Prepare sender my ( $sender, $error ) = Email::Send::SMTP::Gmail->new ( -subject => $subject, -to => $email, -from => $email, -body => $body, # Better to put these in some kind of configuration file # -debug => 1, -smtp => 'smtp.gmail.com', -login => 'kopautomation1@xxx.com', -pass => 'xxx', -layer => 'ssl', -port => '465', -timeout => 1000 ); die "session error: $error" unless ref $sender; # Off we go $sender->send; $sender->bye; __DATA__ <h1>[% subject %]</h1> <p class="date">[% date %] - [% time %]</p> <p>Please fix and redrop or delete the following errors</p> <div class="bad_format"> <h2>Files with bad format</h2> [% FOREACH user IN files.keys %] <h3>User: [% user %] ([% files.$user.size %] files)</h3> <ul class="files"> [% FOREACH file IN files.$user %] <li>[% file %]</li> [% END %] </ul> [% END %] </div>
I am using the Template Toolkit and a template stored in the __DATA__ section of the script to generate the mail. Because the output is now separated from the code, I (you) can make the email arbitrarily complex (like adding images or styles or whatnot) without having to change or clutter the the code with print statement.

Also, I am sure you know this already, whitespace is <s>cheap</s> free!


holli

You can lead your users to water, but alas, you cannot drown them.

In reply to Re^3: count multiple variables in a single array. by holli
in thread count multiple variables in a single array. by flieckster

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.