http://qs321.pair.com?node_id=725157

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

It's Friday afternoon and my brain is fried.

I have a boatload of plain text that contains things that look like http links. If I find one, then I want to wrap it in HTML anchors.

I don't think there's a module that does this, but I welcome suggestions. Otherwise, the spec is in the test below. If someone could show me the error of my ways I'd be a happy man.

Bonus points for converting the first link (http://www.example.com) to http://www.example.com/ in the HREF (add the omitted slash).

use strict; use warnings; my $html = <<END_HTML; Blah blah blah Web: http://www.example.com info.example.com Web: http://info.example.com/ And another Web site: http://another.example.com/ (doesn't always work) Nice blog here: http://blog.example.com/niceblog/ END_HTML my $target = <<END_HTML; Blah blah blah Web: <a href="http://www.example.com">www.example.com</a> job.example.com Web: <a href="http://info.example.com/">info.example.com</a> And another Web site: <a href="http://another.example.com/">another.example.com</a +> (doesn't always work) Nice blog here: <a href="http://blog.example.com/niceblog/">blog.examp +le.com</a> END_HTML use Test::More tests => 1; $html =~ s{(http://(\S+)(?:/\S*)?)}{<a href="$1">$2</a>}g; is($html, $target);

• another intruder with the mooring in the heart of the Perl