在对 URL 数据库执行 file::fetch 时,某些 URL 仅包含顶级域,例如http://google.com。我如何构造我的 if 检查,以便它验证是否有要获取的文件,所以当我创建一个新的 file::fetch 对象时,它不会抛出这个错误:
Use of uninitialized value $path in pattern match (m//) at C:/Perl/lib/File/Spec/Unix.pm line 267.
Use of uninitialized value in string eq at C:/Perl/lib/File/Fetch.pm line 395.
这是我的代码片段,我正在尝试进行一些验证
my $uri_handle = File::Fetch->new(uri => $url);
my $getfile = $uri_handle ->file;
if ($getfile){
my $dir_handle = $uri_handle->fetch( to => $dir ) or die "Couldn't fetch file: $uri_handle->error\n";
#print "[ID:$myid] File fetch completed!\n\n";
}else{
print "[ID:$myid] There is no file to be fetched from $url\n\n";
}
但是 file 方法也失败了,因为它无法在 URL 中检索文件名。
Thread 1 terminated abnormally: Can't call method "file" on an undefined value at C:\test\multihashtest2.pl line 102.