我正在运行一个脚本,从数据库中提取URL并执行file :: fetch().根据我的理解,file :: fetch()仅在要下载的URL中存在文件时才有效.
但是,在我的数据库中,偶尔会有一个URL,其中没有要提取的文件.那么,是否有任何模块可用于检查URL中是否有文件我试图执行文件:: fetch()?
我的脚本中有一行
my $uri_handle = File::Fetch->new(uri => $url);
Run Code Online (Sandbox Code Playgroud)
其中$ url可能http://asiaone.com与没有实际获取的文件类似.
我得到这个错误,我拼命想避免,因为有其他URL主要包含要获取的文件.
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.
Hostname required when fetching from 'http' at C:\test\multihashtest2.pl line 100 thread 2
Run Code Online (Sandbox Code Playgroud)
如何格式化我的正则表达式来检查文件,还是有一个模块可以用来促进这个?
合法的URL将如下所示
http://the.earth.li/~sgtatham/putty/latest/x86/puttytel.exe
Run Code Online (Sandbox Code Playgroud)
从File::Fetch 的手册中有这个标志$File::Fetch::WARN,您可以设置它false以消除错误:
此变量控制是否应对 File::Fetch 内部遇到的错误进行吹毛求疵。
设置为 false 可消除警告。手动检查 error() 方法的输出以查看出了什么问题。
默认为 true。