为什么不在Net :: FTP-> new work中传递Host参数的数组引用?

2 ftp perl libnet

我正在使用Net :: FTP构建FTP客户端.该文档指出新构造函数有一个Host选项,可以引用具有主机的数组,以便依次尝试.我似乎无法让这个工作.我在Windows XP下使用ActivePerl.这是我的代码:

@try_these = ("turing.unh.edu", "euler.unh.edu");
$ftp = Net::FTP->new(Host => @try_these)
or die "Can't connect: $@\n";
Run Code Online (Sandbox Code Playgroud)

这是错误信息:

Can't connect: Net::FTP: Bad hostname 'Host'
Run Code Online (Sandbox Code Playgroud)

Sin*_*nür 6

乍一看,看起来你所要做的就是提供一个参考:

my $ftp = Net::FTP->new(Host => \@try_these);
Run Code Online (Sandbox Code Playgroud)

但这里好像有点片状Net::FTP.我不确定是否有人测试过这个.我现在没有时间调试它,但我只是建议:

my $ftp;
for my $host ( @try_these ) {
    warn "Attempting to connect to '$host'\n";
    $ftp = Net::FTP->new( $host ) and last;
}

die "Could not connect\n" unless $ftp;
Run Code Online (Sandbox Code Playgroud)

更新:我检查了源代码,Net::FTP->new似乎没有检查传递的数组引用.这似乎是代码和文档彼此不匹配的情况.

提交错误报告.

更新:

Subject: Re: [rt.cpan.org #48001] Net::FTP->new(Host => $arrayref) does not work 
Date:    Sun, 19 Jul 2009 11:35:14 -0500 
To:      bug-libnet[...]rt.cpan.org 
From:    Graham Barr  [text/plain 147b]
> > Seems like a mismatch between the code and the docs.
> 
> Not sure where that came from in the docs, Net::FTP has never supported an
> array of hosts

  • 嗯,仍然无法让它工作.当我尝试:我的@try_these =("turing.unh.edu","euler.unh.edu"); 我的$ ftp = Net :: FTP-> new(Host =>\@try_these)或死"无法连接:$ @ \n"; 我得到:无法连接:Net :: FTP:错误的主机名'ARRAY(0x1829da4)' (2认同)