Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

array of sockets in perl

I want to do an array of socket in perl and add a \n, at the end of each socket, I try with &socket[0] but it doesn't 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 the print $socket1[0] "\n"; it will not compile.

but if I don't 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";
like image 683
leykan Avatar asked Dec 14 '22 19:12

leykan


1 Answers

print's filehandle needs to be a glob or a simple scalar (possibly the result of a BLOCK). This should work:

print { $socket1[1] } "\n";
like image 198
Jim Davis Avatar answered Dec 17 '22 10:12

Jim Davis