lampros21_7 has asked for the wisdom of the Perl Monks concerning the following question:

Hi monks My problem is that i get an error:

Missing base argument at C:/Perl/site/lib/HTTP/Response.pm line 93

The code around where it points me to in that module is

if ($req) { # if $base is undef here, the return value is effectively # just a copy of $self->request->uri. return $HTTP::URI_CLASS->new_abs($base, $req->uri); }

My problematic code is:

my $url_name; my $base_url = "http://www.perlmonks.com/"; for (my $c = 0; $c<=$rowcount; $c++) { $webcrawler->get($url_name); my @links = map { $_->[0] } $webcrawler->links; # get Links my $ext1 = ".pdf"; my $ext2 = ".doc"; my $ext3 = ".ps"; my $ext4 = ".txt"; @links = map { URI->new_abs( $_, $base_url ) } @links; @links = map { /^$base_url/ ? $_ : () } @links; @links = grep(!/$ext1|$ext2|$ext4|$ext3$/, @links);

There is more code but am pretty certain the fault comes from somewhere in here. I can't figure out the problem. Can anyone help? Thanks for looking

Replies are listed 'Best First'.
Re: Strange error from Response.pm
by graff (Chancellor) on Mar 10, 2006 at 02:39 UTC
    This is not one of my stronger areas, but my initial guess is that you haven't given us enough information. What sort of object is $webcrawler ? Have you tried stepping through with the debugger to find out why that sub in HTTP::Response is getting an undefined $base? Shouldn't you be assigning something to $url_name before using as an arg to  $webcrawler->get ?

    While not being able to answer your real question, I'll point out that your grep regex should probably be like this:

    my $exts = join( "|", qw/pdf doc ps txt/; @links = grep( !/\.(?:$exts)$/, @links );
    The difference is in the period being treated as a literal period (your version treats it as a wildcard), and having the the set of alternative extension strings match only at the end of a link string (your version only matchs $ext3 (.txt) at the end of the string, and the others can match anywhere in the string).

    (updated to fix grammar)