use Modern::Perl;
use HTML::Parser;
use Regexp::Common qw( URI );
my $parser = HTML::Parser->new
(
default_h => [sub {
my $something = shift;
print $something
}, 'text'],
text_h => [sub {
my $text = shift;
# Guess a bit and add a scheme to www
# This might be bit too aggressive
$text =~ s^ www\.^ http://www.^gi;
# Replace URLs in the text by links
$text =~ s^($RE{URI})^$1^g;
print $text;
}, 'text'],
);
$parser->parse( join "", ) || die $!;
__DATA__
Test data
Some URL without scheme www.perlmonks.org
and a plain URL with scheme http://perl.org
and even ftp ftp://ftpserver.foo.com
and an existing link
####
Test data
Some URL without scheme www.perlmonks.org
and a plain URL with scheme http://perl.org
and even ftp ftp://ftpserver.foo.com
and an existing link