Thank you to all who replied.

I ended up solving this issue with an entirely different method. Much thanks goes to Ikegami for putting me on the right path. Here's the final code, though it's not been made into an object method yet.
#!/usr/bin/perl $|++; use strict; use warnings; our $DEBUG = 1; my $query = $ARGV[0] || 'default data'; print client($query); sub client { use IO::Socket; # <- here for when this sub grows up to become an ob +ject method # do some basic setup stuff my $info = shift; return "No info!" unless ($info); my @ips = ('XXX.XXX.XXX.X0','XXX.XXX.XXX.X1','XXX.XXX.XXX.X2'); my $port = XXXX; # grab an IP randomly my $index = int(rand(scalar @ips)); # try to connect once for each IP my $sock; for (my $counter = 0; $counter < scalar @ips; $counter++) { # debug output print "Trying $ips[$index]... " if ($DEBUG); # try to connect $sock = IO::Socket::INET->new( PeerAddr => $ips[$index].':'.$port +, Blocking => 1, Timeout => 1, ### The key param t +hat I had been missing!!! ); # success! if ($sock) { print "OK!\n" if ($DEBUG); last; } # failure print "Nope\n" if ($DEBUG); # get previous IP (loops around if negative, pretty sweet) $index--; } # return error if all 3 failed return "no sock!" unless ($sock); # write to socket print $sock $info.$/ or die "$!"; # read from socket and close sysread $sock, my ($text), 10000; close($sock); return $text; }

---
It's all fine and dandy until someone has to look at the code.

In reply to Re: Signal handlers and scoped variables, or Nested subs? by kwaping
in thread Signal handlers and scoped variables, or Nested subs? by kwaping

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.