in reply to Re: Module's .pm errors
in thread Module's .pm errors

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

Replies are listed 'Best First'.
Re: Module's .pm errors
by chromatic (Archbishop) on Feb 27, 2004 at 05:50 UTC

    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 ... }
Re: Module's .pm errors
by Roger (Parson) on Feb 27, 2004 at 05:51 UTC
    @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 ... }