我想在perl中做一個套接字數組,並在每個套接字的末尾添加一個\n
,我嘗試使用&socket[0]
,但它不起作用。perl中的套接字數組
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";
當我做print $socket1[0] "\n";
它不會編譯。
,但如果我不使用它工作的數組:
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";
'@ cppcoder'沒有,因爲如果我這樣做'$打印SOCKET1 [0] 「\ n」;'它會打印'socket1 [0]',然後打印'「\ n」'但我想在套接字中加入'「\ n」'。 – leykan 2014-10-09 09:55:45
二級備註:我建議不要在'die'消息的末尾添加換行符'\ n',因爲這會隱藏行號信息。 – Miller 2014-10-09 19:16:51