in reply to Wait and retry loop without goto

A do-while loop should do the job without the goto:

my $output; my $tries = 0; do { $output = `expect -f show_running_config.exp $router->[$IP]`; if($?){ # subshell returns error $tries++; # count a try sleep 5; # pause } } while( $? and $tries < 4 ); # loop again if error and more tries # was the last try unsuccessful? if($?){ # last try was an error, ran out of tries print "Unable to connect after $tries tries\n"; exit; } # go on to handle the response in $output

Aaron B.
Available for small or large Perl jobs and *nix system administration; see my home node.

Replies are listed 'Best First'.
Re^2: Wait and retry loop without goto
by samuelk1 (Initiate) on May 15, 2015 at 03:13 UTC
    Thanks, I didn't think of that. Works great.