I am a true believer of abstracting your code into subroutines, but for this it just seems like a waste of time. Also, why bother writing the data back out to the same file? Just log the results to a new file. Anyways, the problem you are having is that you are not splitting each line. Since you didn't specify which email address you are using, i'll have to assume you meant all of them. If you know exactly which ones you want, just use split with an array slice:
open (FILE, '<', 'prev.txt') or die "Can't open prev.txt\n"; while (<FILE>) { my @email = (split('\s',$_))[1..3]; for (@email) { # send email # log results } }
If you don't know which fields will be email addresses, you can bring Email::Valid along for the ride:
use Email::Valid; open (FILE, '<', 'prev.txt') or die "Can't open prev.txt\n"; while (<FILE>) { my @stuff = split; for (@stuff) { next unless Email::Valid->address($_); # send email to $_ # log results } }
Finally, please consider using MIME::Lite to send the emails. It's really easy to use and it really rocks. :)

jeffa

L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)

In reply to Re: Passing Arrays to Subroutines by jeffa
in thread Passing Arrays to Subroutines by shemyaza

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.