in reply to Net::FTP and standard output

As already mentioned, use the message method (on everything but new(), and $@ for new), but also, I find something like this style more readable than all those nested if/else blocks:
{ my $ftp = Net::FTP->new(...); print("Can't connect: $@\n"), last unless $ftp; my $status = $ftp->login(...); # use 'return' instead of 'last' if it # suits your purposes better print("failed to login:",$ftp->message), last unless $status; $status = $ftp->cwd(...); print("failed to chdir:",$ftp->message), last unless $status; ... }

Replies are listed 'Best First'.
Re: Re: Net::FTP and standard output
by chip (Curate) on Jan 03, 2002 at 05:40 UTC
    Isn't this the sort of thing that eval is good for?

    eval { my $ftp = Net::FTP->new(...) or die "Can't connect: $@\n"; $ftp->login(...) or die "failed to login:".$ftp->message; $ftp->cwd(...) or die "failed to chdir:".$ftp->message; ... }; warn $@ if $@; # or whatever

    UPDATE: Shortened and fixed typo, per runrig.

        -- Chip Salzenberg, Free-Floating Agent of Chaos