develooper Front page | perl.beginners | Postings from February 2002

Sockets in an array

Thread Next
Girish Chandran
February 22, 2002 14:06
Sockets in an array
Message ID:

I have the following problem.

I am trying to open multiple sockets to multiple IP address. 
I want to use the same piece of code to do that.
The IP addresses and port numbers are stored in a file. 

The program:
I read the file, open the sockets in sequence. 
The sockets (globs/handles) are stored in an array. 

The error:
However when I try to write to the sockets by using the array index, I get 
an error. 

Here is the code snippet. 

use IO::Socket ;
$i = 0;
foreach $line (@address){
   chop ($line);
   ($host, $port) = split(/\|/, $line);
   $address = $host. ":" .$port;
   $newsocket[$i] = IO::Socket::INET->new("$address") or die $@;
# The sockets are opened fine.
# Print a command to the socket.
   print $newsocket[$i] $command;

It is the print command that give a compile error, saying "Scalar  found 
where an operator expected"

Can you please tell me what I am doing wrong. Thanks in advance.


Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About