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

Am a real novice at this language and do not understand how to utilize the warn function in my FTP script so it will not die when it encounters a down site, etc. I am using a file handle that is read line by line to FTP encrypted and nonencrypted data to various sites. Any suggestions as to books or sites I could visit to find some examples? Todate my WEB searches have been fruitless.

Replies are listed 'Best First'.
Re: Net::FTP and the warn function
by cwest (Friar) on Jul 19, 2000 at 19:04 UTC
    Ok, I'm going to assume that you have something like:
    my $ftp = Net::FTP->new( ... ) or die $!;
    And you don't feel like dying, you just want to say 'Hey, this thang ain't workin'.

    Well, here's one solution:

    my $ftp = Net::FTP->new( ... ); if ( defined $ftp ) { $ftp->func1( ... ); $ftp->func2( ... ); $ftp->quit; } else { warn "Hey, this thang ain't workin! $!\n"; }
    or, another way to do it might be to create a SIG handler... although I'm not fond of it personally:
    $SIG{__DIE__} = sub { warn shift and exit }; my $ftp = Net::FTP->new( ... ) or die $!;
    That's kinda gracefull, but it will quit your process... another solution could be:
    sub ftp_stuff { my $ftp_ref = shift; $ftp_ref->func( ... ); $ftp_ref->quit; } my $ftp = Net::FTP->new ? ftp_stuff $ftp : warn $!;
    I hope I've helped you out.

    Enjoy!

    --
    Casey