Further, if this is the case

for my $file (`ls -l /some/dir`) { ... }

then you may be interested in  ls -1, or better still, for a pure Perl method the  readdir function. From perlfunc:

opendir(DIR, $some_dir) || die "can't opendir $some_dir: $!"; @files= grep { -f "$some_dir/$_" } readdir(DIR); closedir DIR;

I use the following subroutine to wrap around mailx, which you may find to be a useful starting point

# # mailit - send an email using mailx. Accepts either a $body or a path + # to a file # # Args: # $subject - email subject # either: # $body - body of email in scalar var, or # $fname - path to file to send. # @emails - list of email addresses to send email to # sub mailit { my ( $subj, $body, $fname, @email ) = @_; my($mailcmd) = "mailx -s\"$subj\""; die "Invalid mailit args\n" unless ($subj and ($body or $fname +)); if ($body) { foreach ( @email ) { open( PI, "|$mailcmd $_" ) or warn "Pipe to ma +ilx failed: $mailcmd\n"; print PI $body; print PI "\n.\n"; close PI; } } elsif ($fname) { die "Bad mailit path $fname\n " unless -e $fname; foreach ( @email ) { `$mailcmd $_ < $fname` or warn "bad mailx resp +onse: $?, $!"; } } }
Disclaimer: modified for posting, so untested.

mailit(), in conjunction with readdir, should do what you want.

Hope this helps, bm.


In reply to Re: Re: mailx by bm
in thread mailx by karu1975

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.