What do you mean by "good way"? There are allways more ways to do it...

If the above code works, it works. Not that there are things to improve; for example, you fill an array, which you later join. Why not join the lines directly?A (slightly rewriten) version of your code could be:

#!/usr/bin/perl use strict; use warnings; use POSIX; use Win32::OLE; open my $source, "<", "//reports/test.txt" or die "cannot open file: $!\n"; my $ies_details; while( <$source> ) { next unless substr $source,11,4 =~ /\d{4}/; next unless substr $source,79,10 =~ /\d{10}/; $ies_details .= $_; } my $Outlook = Win32::OLE->GetActiveObject('Outlook.Application') || Win32::OLE->new('Outlook.Application'); my $mailitem = $Outlook->CreateItem(0) or die "Outlook is not running, cannot send mail.\n"; my $procdate = POSIX::strftime('%m/%d/%Y %H:%M', localtime); $mailitem->{'To'} = 'test@yahoo.com'; $mailitem->{'Cc'} = 'test@test.com'; $mailitem->{'Subject'} = 'Summary Report ' . $procdate; $mailitem->{'Body'} = "Below is a summary\n\n" . "-----------------------------------------\n\ +n" . $ies_details; $mailitem->{'Importance'} = 0; # 2=high, 1=normal, 0=low $mailitem->Send;

Paul


In reply to Re: Add Results to Outlook body by rev_1318
in thread Add Results to Outlook body by drodinthe559

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.