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

RE: Sockets in an array

Thread Previous | Thread Next
From:
Nikola Janceski
Date:
February 22, 2002 14:13
Subject:
RE: Sockets in an array
Message ID:
1449413DA482D311B67000508B5A12F50592DDC7@nyexchange01.summithq.com
I have run into this situation before, but never found a solution..
But now that I see the problem try the following prints:

print ${$newsocket[$i]} $command;
print *{$newsocket[$i]} $command;
print *newsocket[$i] $command;

I think the second one might work... let us know how it goes.

-----Original Message-----
From: Girish Chandran [mailto:girish@localhost.localdomain]
Sent: Friday, February 22, 2002 4:53 PM
To: beginners@perl.org
Subject: Sockets in an array


Hi,

I have the following problem.

Context:
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;
   $i++;
}

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.

Girish

-- 
To unsubscribe, e-mail: beginners-unsubscribe@perl.org
For additional commands, e-mail: beginners-help@perl.org

----------------------------------------------------------------------------
--------------------
The views and opinions expressed in this email message are the sender's
own, and do not necessarily represent the views and opinions of Summit
Systems Inc.


Thread Previous | Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About