Given the following: (look familiar?)
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 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");} 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; }
I can't seem to get the hang of iteration using a FOR loop. Here's the output:
[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]$
What am I missing?

In reply to How to wrap a subroutine call in a for loop by Tuna

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.