【问题标题】:Active perl multiple sockets活动 perl 多个套接字
【发布时间】:2014-01-07 04:50:24
【问题描述】:

好吧,我在活动 perl 中创建多个套接字时遇到了问题。 这是我在这里尝试做的一个例子。

for($i=0;$i<$botcount;$i++){
my ($socket[$I],$client_socket[$I]);
my $socket[$I] = new IO::Socket::Socks(
ConnectAddr=>$chatip,
ConnectPort=>$chatport,
);
}

不幸的是,这给了我一个错误。

我知道我可以重命名它,但这会产生很多不必要的空间。 有人可以帮我吗?

【问题讨论】:

  • 你首先需要use strict; use warnings;,你需要在for循环之外创建你的数组,最后,变量$i与$I不同,因为perl区分大小写

标签: perl sockets


【解决方案1】:
 #!/usr/bin/perl -w
 use strict;
 use diagnostics; #this will explain warnings/errors

 #declare your variables here
 my ($botcount, $chatport, $chatip);
 my @client_socket;
 my @socket;
 foreach my $i (0..$botcount){
      $socket[$i] = new IO::Socket::Socks(
           ConnectAddr => $chatip,
           ConnectPort => $chatport
      );
 }

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-07-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2011-08-11
    • 1970-01-01
    相关资源
    最近更新 更多