Take me over?
NAME
URI::Find - Find URIs in arbitrary text
SYNOPSIS
use URI::Find;
$how_many_found = find_uris($text, \&callback);
DESCRIPTION
This module does one thing: Finds URIs and URLs in plain text. It finds them quickly and it finds them all (or what URI::URL considers a URI to be.)
Functions
URI::Find exports one function, find_uris(). It takes two arguments, the first is a text string to search, the second is a function reference.
The function is a callback which is called on each URI found. It is passed two arguments, the first is a URI::URL object representing the URI found. The second is the original text of the URI found. The return value of the callback will replace the original URI in the text.
EXAMPLES
Simply print the original URI text found and the normalized representation.
find_uris($text,
sub {
my($uri, $orig_uri) = @_;
print "The text '$orig_uri' represents '$uri'\n";
return $orig_uri;
});
Check each URI in document to see if it exists.
use LWP::Simple;
find_uris($text,
sub {
my($uri, $orig_uri) = @_;
if( head $uri ) {
print "$orig_uri is okay\n";
}
else {
print "$orig_uri cannot be found\n";
}
return $orig_uri;
});
Wrap each URI found in an HTML anchor.
find_uris($text,
sub {
my($uri, $orig_uri) = @_;
return qq|<a href="$uri">$orig_uri</a>|;
});
SEE ALSO
L<URI::URL>, L<URI>, RFC 2396
AUTHOR
Michael G Schwern <schwern@pobox.com> with insight from Uri Gutman and Jeff Pinyan.