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. |