John W. Krahn said:
> 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';
>      }

Ah, got it. Do I just expand on the failure and completed message and add
in what I had before?

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

Got it.

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

Will do.

Lastly, the scripts fails when I uncomment $options, saying verbosity
needs a number, when I have it -v5 --print-statistics. Is this the wrong
way to pass the option?

Gavin.


-- 
Just getting into the best language ever...
Fancy a [EMAIL PROTECTED] Just ask!!!

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