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

I've installed WWW::Mechanize .072, libwww-perl-5.76, and HTML::Parser 3.35, but when I run a perl script that uses these it gives me:
Use of uninitialized value in pattern match (m//) at /usr/lib/perl5/si +te_perl/5.8.0/HTTP/Cookies.pm line 45. Missing base argument at /usr/lib/perl5/site_perl/5.8.0/HTTP/Response. +pm line 57
I have reinstalled the modules, does anyone know what modules these errors are from and where I can get information on how to fix this? Thanks

Replies are listed 'Best First'.
Re: Module's .pm errors
by Roger (Parson) on Feb 27, 2004 at 04:22 UTC
    The following is where the error comes from in Cookies.pm -
    sub add_cookie_header { my $self = shift; my $request = shift || return; my $url = $request->url; my $scheme = $url->scheme; unless ($scheme =~ /^https?\z/) { # LINE 45 LWP::Debug::debug("Will not add cookies to non-HTTP requests"); return; } my $domain = _host($request, $url); .....

    I suspect your script is not working, can show us your script?

      of course, here it is:
      #!/usr/bin/perl -w use HTML::Parser; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); $p = HTML::Parser->new(); @sites="http://www.frozenhosting.com"; for( $i=1; $i<100000; $i++) { $mech->get( $sites[$i] ); $mech->content()=$html; $mech->find_all_links(); $link->url_abs()=@sites; open(FILE,">/crawled/$i.txt"); $p->parse($html); print FILE "$sites[$i]\n"; print FILE "$html"; close(FILE); }
      Thanks

        The first element of an array has an index of 0, not 1. Besides that, it's likely you don't want to fetch an undefined URL 100,000 times. Perhaps this loop will work better:

        for my $i (0 .. $#sites) { # code as before ... }
        @sites="http://www.frozenhosting.com"; for( $i=1; $i<100000; $i++) { $mech->get( $sites[$i] ); .... $mech->content()=$html; $mech->find_all_links(); $link->url_abs()=@sites;

        Looking at your code, what are you trying to achieve? Your immediate problem is because:
        1) @sites = "http://www.frozenhosting.com"; builds a one element list, with index starting at 0. Yet you are trying to fetch it with index $i starting from 1, which is undefined of course. And because you are trying to get an undefined site, you get the warning and error messages.
        2) You got the assignments the other way round.

        Your script should look something like below to work properly, and man, you have a lot of readings to do on Perl, and you should start by doing some tutorials at Perl Monks. :-)
        use strict; use warnings; use HTML::Parser; use WWW::Mechanize; my $mech = WWW::Mechanize->new(); my $p = HTML::Parser->new(); my @sites = ( 'http://www.frozenhosting.com' ); for my $site (@sites) { $mech->get($site); my $html = $mech->content(); my @links = $mech->find_all_links(); $p->parse($html); ... etc ... }