in reply to VB "On Error" Equivalent in Perl
- Milleruse Carp qw(croak); use English qw(-no_match_vars); use Net::FTP; use Time::HiRes qw(sleep); use strict; my $MAX_TRIES = 15; my $ftp; TRY: for my $try (1..$MAX_TRIES) { # If successful, we're done. eval { $ftp = Net::FTP->new("some.host.name", Debug => 0) or die "Cannot connect to some.host.name: $@"; last TRY; }; # Report non-recoverable failure if no more tries croak( $EVAL_ERROR ) if $try == $MAX_TRIES; # Try again after a nap (approximate fibonacci) sleep( rand (1.618 ** $try) ); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: VB "On Error" Equivalent in Perl
by erroneousBollock (Curate) on Nov 29, 2007 at 01:28 UTC | |
by wind (Priest) on Nov 29, 2007 at 01:41 UTC |