in reply to Signal handlers and scoped variables, or Nested subs?

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.