Tuna has asked for the wisdom of the Perl Monks concerning the following question:
I am trying to rewrite this routine so that it will make 3 atempts to succeed before "return &error()". Why doesn't this work?sub establishSession { my @sshPort; if ($sshPort =~ /(\d+)/) {@sshPort = ("port", $1)} else {return &error ("invalid port number");} &xferOpen ('SESSION', $clusterHost,"compression", "yes", @sshPort) || return &error("couldn't connect to $clusterHost : $xferError"); return $success; }
I can't seem to get the hang of iteration using a FOR loop. Here's the output:sub establishSession { my @sshPort; if ($sshPort =~ /(\d+)/) {@sshPort = ("port", $1)} else {return &error ("invalid port number");} for (my $tries = 1; $tries < 4; $tries++) { print "Attempt $tries to connect\n"; &xferOpen ('SESSION', $clusterHost,"compression", "yes", @sshPort); } return &error("couldn't connect to $clusterHost : $xferError"); return $success; }
What am I missing?[ssesar@burl-dhcp152-211 20010808]$ ./pushproc-devel-20010808.pl Attempt 1 to connect SAxfer.pl: spawning timeout 3 ssh '-oBatchMode yes' -x -n -p 22 -c 3de +s '-oCompression yes' localhost /bin/true Attempt 2 to connect Attempt 3 to connect p pushproc.pl: ERROR: couldn't connect to localhost : process timed out +after 3 seconds pushproc.pl: disconnecting from host (localhost) pushproc.pl: reactivation of localhost failed pushproc.pl statistics: 1 hosts attempted 0 host(s) succeeded 1 host(s) failed [ssesar@burl-dhcp152-211 20010808]$
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to wrap a subroutine call in a for loop
by Zed_Lopez (Chaplain) on Aug 09, 2001 at 02:03 UTC |