gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-12-02 09:01:11 26 4
gpt4 key购买 nike

我正在使用 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";

这是错误消息:

Can't connect: Net::FTP: Bad hostname 'Host'

最佳答案

乍一看,您所要做的就是提供一个引用:

my $ftp = Net::FTP->new(Host => \@try_these);

但是这里的 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;

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

Bug report已提交。

更新:

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

关于perl - 为什么在 Net::FTP->new 中传递 Host 参数的数组引用不起作用?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1148744/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com