Gavin Henry wrote:
It looks like 99% of the code in both blocks is exactly the same.  You
should
factor out duplicated code.

my $msg = $backup ? 'failed' : 'completed';

my %mails = (
    To      => $to,
    From    => $from,
    Subject => "Remote backup $msg from $ENV{HOSTNAME} on $time",
    Message => "The remote backup has $msg on $ENV{HOSTNAME} on $time
with
the command:\n\n $rdiff @args\n"
    );
sendmail( %mails );
# finish message
print "\n", $separator, "Remote backup $msg on $time. E-mail sent with
details.\n", $separator;

Thanks John and Chris. Chris, I have gone for John method of using the $seperator, as I will use that more in this script when I add more features, thanks for the pointer on here documents though.

I have taken on board all your suggestions, but I still have two questions:

1. How does the above code get the return code from rdiff to tell if it
failed or passed?

The same way it did before.

Is this the $backup ? part, i.e. failed first, then
completed second?

It seems like you may be confused by the conditional operator. The statement:

my $msg = $backup ? 'failed' : 'completed';

Is short for:

my $msg;
if ( $backup == 0 ) {
    $msg = 'completed';
    }
else {
    $msg = 'failed';
    }

2. use POSIX qw(strftime); I got this from Perl Cookbook. I take it this
is calling the POSIX strftime and putting it in a list,

No, this is telling perl that the only function we want to import from the POSIX module is 'strftime'.


so when I select
%T etc. it is picking it from the list? Why does it fail if I put use
POSIX; and put qw(strftime); somewhere else.

Because the list of function names must follow the module name.

perldoc -f use



John
--
use Perl;
program
fulfillment

--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
<http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to