title: perl outlook to print the last word of an email header
body: <p>I have a script that matches part of an email subject line, then prints the email body to an output file for sorting etc, the emails are then moved to a sub folder.
   what i would like to do is get the last word of the subject line (which is a name) and idealy add that word to the end of each line of the email body, this is what i have at present, it successfully prints the email body's to output and moves them as well.</p>
  
  <pre><code>&lt;code&gt;
  #!/usr/bin/perl
  use strict;
  use warnings;
  #use diagnostics;
  
  use Win32::OLE;
  use Win32::OLE::Const 'Microsoft Outlook';
  
  my $filename = 'c:\\test.txt';
  open( my $output_fh, "&gt;", $filename ) or die $!;
  
  my $outlook = Win32::OLE-&gt;new('Outlook.Application')
      or die "Failed Opening Outlook.";
  
  my $namespace    = $outlook-&gt;GetNamespace("MAPI");
   my $folder = $namespace-&gt;Folders("inbox");
  my $tofolder = $namespace-&gt;Folders("archive");
  my $items        = $folder-&gt;Items;
  
  foreach my $msg ( $items-&gt;in ) {
      if ( $msg-&gt;{Subject} =~ m/^test test test / ) {
      my @name = split(/ /, $msg);
          print $name[-1] . "\n";
          print {$output_fh} $msg-&gt;{Body};
          $msg-&gt;Move($tofolder );
      }
  }
  
  close($output_fh);
  &lt;code&gt;
  </code></pre>
  
  <p>this warning appears 'Win32::OLE=HASH(0x2a9432c)'</p>
  
  <pre><code>&lt;code&gt;
   the Email subject lines will be 
   test test test micky
   test test test jony
   test test test dave
   test test test adam
  so i would like the name added to each line of the email body
  
  &lt;code&gt;
  </code></pre>