dynamopsychism has asked for the wisdom of the Perl Monks concerning the following question:

Hi- I'd like to use IO::Socket::INET to open up a bunch of connections to different ports on a server. I was going to make an array such that:
my @socket; for ($counter = 0; $counter < @remote_port; ++$counter) { $socket[$counter] = IO::Socket::INET->new(PeerPort => $remote +_port[$counter]
but when I try to print to one of the sockets with any of the following:
print $socket[$counter] "sp100\r";
or
print($socket[$counter], "sp100\r");
I get various errors, such as:
String found where operator expected at ./moxaip.pl line 42, near "] "sp100\r"" or the output:
0x821bcd4)sp100
I understand why both of these are happening; how do I get the damned thing to print to the socket?

Replies are listed 'Best First'.
Re: IO::Socket and variables
by no_slogan (Deacon) on May 22, 2001 at 02:13 UTC
    print { $socket[$counter] } "foo\n"

    or

    $socket[$counter]->print("foo\n")

    or even

    $sock = $socket[$counter]; print $sock "foo\n"

      Or
      sub socket_print { my ($socket, $message) = @_; print $socket $message; }