Sara wrote:
I am trying to extract links along with HTML tags <a href=blah> from a list, 
but it's not working on my XP machine with Active State Perl 5.0.6
Kindly help.

################# CODE START ####################

my @array = qq|
<body><a href="http://www.mydomain.com";><img alt="Free Hosting, Freebies" border=0 
src="http://www.mydomain.com/images/logo2.gif";></a>
|;
#extract LINKS (no image links) only <a href="http://www.mydomain.com";>

my @get = grep {/<a .*?>/} @array;
print "@get\n"

################### CODE END ###################

I'm not sure why you're assigning a string to an array...

(completely untested)

my $html = <<HTML;
<body><a href="http://www.mydomain.com";><img alt="Free Hosting, Freebies" border=0 src="http://www.mydomain.com/images/logo2.gif";></a>
HTML


use HTML::LinkExtractor;

my $lx = new HTML::LinkExtractor();
$lx->parse(\$html);

for my $link( @{$lx->links} ) {
  if( $$link{tag} !~ /img/i ) {
    my $href = $$link{href};
    print $href->as_string();
  }
}

__END__


-- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>




Reply via email to