Beefy Boxes and Bandwidth Generously Provided by pair Networks
No such thing as a small change

Answer: How do I replace a URL with a clickable hyperlink?

by rob_au (Abbot)
on Feb 14, 2002 at 11:28 UTC ( #145424=categorized answer: print w/replies, xml ) Need Help??

Q&A > regular expressions > How do I replace a URL with a clickable hyperlink? - Answer contributed by rob_au

There is a module specifically built for this task - URI::Find. eg.

#!/usr/bin/perl -Tw use URI; use URI::Find; use strict; my $text = "... long string with lots of URLs ..."; find_uris($text, sub { my ($find_uri, $orig_uri) = @_; my $uri = URI->new( $orig_uri ); $uri = $uri->canonical->as_string; return '<a href="' . $uri . '">' . $uri . '</a>'; }); print $text, "\n"; exit 0;

Note that the CPAN documentation for URI::Find is out-of-date with the newest version (0.04) exporting only the one function, find_uris, which takes two arguments, the string to be searched and a function reference.


perl -e 's&&[@.]/&&s&.com.&_&&&print'

Log In?

What's my password?
Create A New User
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others imbibing at the Monastery: (3)
As of 2018-01-21 21:45 GMT
Find Nodes?
    Voting Booth?
    How did you see in the new year?

    Results (230 votes). Check out past polls.