Girish Chandran wrote: > > 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 warnings; use strict; > use IO::Socket ; > $i = 0; my $i = 0; > foreach $line (@address){ for my $line ( @address ) { > chop ($line); chomp $line; > ($host, $port) = split(/\|/, $line); my ( $host, $port ) = split /\|/, $line; > $address = $host. ":" .$port; my $address = "$host:$port"; > $newsocket[$i] = IO::Socket::INET->new("$address") or die $@; $newsocket[$i] = IO::Socket::INET->new( $address ) or die $@; > # The sockets are opened fine. > # Print a command to the socket. > print $newsocket[$i] $command; perldoc -f print [snip] Note that if you're storing FILEHANDLES in an array or other expression, you will have to use a block returning its value instead: print { $files[$i] } "stuff\n"; print { $OK ? STDOUT : STDERR } "stuff\n"; print { $newsocket[$i] } $command; > $i++; > } John -- use Perl; program fulfillment -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]