There are a couple ways you could do this - what I'd probably do is set a constant $MAX_RETRIES and then either locally decrement this, or count a loopcounter up to this, using last if a connection is made.
For example: (untested code)
my $MAX_RETRIES = 3; foreach (@host) { foreach $attempt ( 1 .. $MAX_RETRIES ) { my $sock = IO::Socket::INET->new(PeerAddr => $_, PeerPort => $port, Proto => 'tcp', timeout => '10') and $connected = 1; last if $connected; } unless $connected print "$_ is NOT connected.\n" && run_fix(); }
You could extend this to have the script sleep for a set number of seconds before retries, which is maybe a good idea if there's lag involved on the network.
Just some quick ideas ..
Hope that helps.
-- Foxcub
In reply to Re: Trying Not To Cause an Infinite Loop
by Tanalis
in thread Trying Not To Cause an Infinite Loop
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |