Ben Edwards wrote:
> I have a perl script that uses FTP.  If the ftp server can not be
> conected to I want to write to a log file and exit with a return code
> of 1.
> 
> Something like
> 
>    my $ftp = Net::FTP->new( $remote_host ) or {
>      print LOGFILE "failed to connect to $remote_host\n"
>      return(1);
>    };
> 
> But this does not work.  So how do I do 2 statements for an or?

I did this backwards, it prints on success, but you get the idea. BTW,
the return won't work unless this code is within a subroutine. Even
though it spits an error because of this, you can see that both
statements get processed:

#!/usr/bin/perl -w

use strict;
use Net::FTP;

my $remote_host = 'localhost';

my $ftp = Net::FTP->new ($remote_host);

if ($ftp) {
        print "Connected to $remote_host\n";
        return(1);
}


...returns this:

%./ftptest.pl
Connected to localhost
Can't return outside a subroutine at ./ftptest.pl line 12.

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


Reply via email to