Perl socket array

I want to make an array of sockets in perl and add \n, at the end of each socket, I try with &socket[0], but it does not work.

my @socket1;
$socket1[0] = IO::Socket::INET->new(
    Type     => SOCK_STREAM,
    PeerAddr => "127.0.0.1",
    Proto    => "tcp",
    PeerPort => $dbase_param{camera_stream}
) or die "Cannot open socket on port " . $dbase_param{camera_stream} . ".\n";

print $socket1[0] "\n";

when I do print $socket1[0] "\n";, it will not compile.

but if I do not use an array, it works:

my $socket1;
$socket1 = IO::Socket::INET->new(
    Type     => SOCK_STREAM,
    PeerAddr => "127.0.0.1",
    Proto    => "tcp",
    PeerPort => $dbase_param{camera_stream}
) or die "Cannot open socket on port " . $dbase_param{camera_stream} . ".\n";

print $socket1 "\n";
+4
source share
3 answers

printfilehandle should be glob or a simple scalar (possibly the result of BLOCK). This should work:

print { $socket1[1] } "\n";
+5
source

Try the following syntax:

$socket1[0]->print("\n");
+5
source

syswrite() send(). , , . IO:: Socket:: INET,

$socket[1]->print("\n");
$socket[1]->syswrite("\n");
$socket[1]->send("\n");
+2

All Articles