Marcus Lim
Marcus Lim

Reputation: 577

Perl File::Fetch failed because the URL doesn't have a file part

I am running a script that pulls URLs from a database and performs a file::fetch(). From my understanding, file::fetch() only works when there is really a file in the URL to be downloaded.

However, in my database there is the occasional URL where there is no file to be fetched. So, is there any module I can use to check that there is a file in the URL I am attempting to perform a file::fetch()?

There is a line in my script

my $uri_handle = File::Fetch->new(uri => $url);

where the $url may be something like http://asiaone.com with no file to actually be fetched.

And I get this error which I am desperately trying to avoid because there are other URLs that mostly contain files to 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.
Hostname required when fetching from 'http' at C:\test\multihashtest2.pl line 100 thread 2

How can I format my regular expression to check for files or is there a module I can use to facilitate this?

A legitimate URL would be something like below

http://the.earth.li/~sgtatham/putty/latest/x86/puttytel.exe

Upvotes: 5

Views: 921

Answers (1)

Tudor Constantin
Tudor Constantin

Reputation: 26871

From the manual of File::Fetch there is this flag, $File::Fetch::WARN, which you can set to false in order to silence the errors:

This variable controls whether errors encountered internally by File::Fetch should be carp'd or not.

Set to false to silence warnings. Inspect the output of the error() method manually to see what went wrong.

Defaults to true.

Upvotes: 3

Related Questions