Okay, so, I grabbed the example from HTML::LinkExtor pod,
and, here's the problem. I put everything into a subroutine
(my first excursion into subs), and everything works great the
first call through. (in other words, subname($eh, $what) works,
but when you execute the identical code a second time, it doesnt
work.). So here is the symptom. The subroutine returns an array,
and the array is populated the first time just fine, but the
second+ time around, it wont get populated. Any Ideas?
#!/usr/bin/perl -I/tmp/perl/libwww-perl-5.53/lib/
use 5.005;
use strict;
use LWP::UserAgent;
use HTML::Parser;
use HTML::LinkExtor;
use URI;
use URI::URL;
my $ua = LWP::UserAgent->new;
sub extractlinks
{
my($url, $linktype) = @_;
my @sublinks = ();
sub callback
{
my($tag, %attr) = @_;
return if $tag ne $linktype;
push(@sublinks, values %attr);
}
my $p = HTML::LinkExtor->new(\&callback);
my $res = $ua->request(HTTP::Request->new(GET => $url), sub {$p->p
+arse($_[0])});
my $base = $res->base;
return map { $_ = url($_, $base)->abs; } @sublinks;
}
my @links = extractlinks("http://www.ebitch.cc", "a");
my @totallinks;
push @totallinks, @links;
for(my $i = 0; $i < $#links; $i++)
{
push @totallinks, extractlinks($links[$i], "a");
}
print join("\n", @totallinks), "\n";
When running with -w mode, I get the following errors (which I know have something to do with this, but I'm not sure what.)
Variable "$linktype" will not stay shared at lnkchk.pl line 22.
Variable "@sublinks" will not stay shared at lnkchk.pl line 23.
thanks in advance,
E-Bitch
Edit: chipmunk 2001-06-27
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.