steve1040 has asked for the wisdom of the Perl Monks concerning the following question:

Dear PerlMonk I'd like to add an email notification when modified date is old. My system admin told me to use Mailx (mailx -s "Subject" emailaddress@something.xxx) Here are the two lines that check the 2 variables in question. How would I write Perl code so that each check sends a email. ##My Code Start###### # If lacecurrent is not equal to today then do not run die if ( -M $currentlist_file > 1); die if ( -M $pre_historical_file > 2); ###My Code Stop####### Thanks Steve

Replies are listed 'Best First'.
Re: Use Mailx with Perl
by Corion (Patriarch) on Feb 05, 2015 at 12:38 UTC

    Personally, instead of using mailx, I would use MIME::Lite to send the mail. If you really want to use mailx (maybe because your system administrator will support you better then), see system for how to run an external program, and/or open resp. perlipc for how to supply data to STDIN of a child process.

Re: Use Mailx with Perl
by soonix (Chancellor) on Feb 07, 2015 at 19:41 UTC
    I'd do something like the following (untested)
    my @msg; push @msg, "$currentlist_file too old" if ( -M $currentlist_file > 1); push @msg, "$pre_historical_file too old" if ( -M $pre_historical_file + > 2); if (@msg) { open(my $mail, '|-', "/usr/bin/mailx ...") or die "failed opening +pipe to mailx"; # salutation and valediction :-) unshift @msg, 'Dear Steve,', ''; push @msg, '', 'I beg to remain, Sir, your most humble and obedien +t servant,', "\t$0"; print $mail, join ("\n", @msg); close $mail; }