| [reply] |
Using the advice of Aristotle (and, no offense intended,
ignoring the advice of Abigail-II (not generally
recommended)), here is some code for
you. (chalk it up to a lazy Sunday ;))
use strict;
use warnings;
use CGI qw(a);
use URI::Find::Schemeless;
my $text = do {local $/;<DATA>};
my $finder = URI::Find::Schemeless->new(
sub { return a{href=>$_[0]->abs},$_[1] }
);
$finder->find(\$text);
print $text;
__DATA__
stuff stuff
http://foo.com/bar/qux.html stuff
stuff stuff
http://bar.com/baz.cgi?foo=bar stuff
stuff stuff
www.perlmonks.org/?node_id=255439
Personally, i love using CGI.pm to mark up text with HTML.
Sure it may be an elephant, but it's a tried, true, and
tested elephant! ;)
CORRECTION: I realized that I had the arguments to
CGI::a wrong - i swapped $_[0] and
$_1 to correct the mistake.
jeffa
L-LL-L--L-LL-L--L-LL-L--
-R--R-RR-R--R-RR-R--R-RR
B--B--B--B--B--B--B--B--
H---H---H---H---H---H---
(the triplet paradiddle with high-hat)
| [reply] [d/l] |
s[((\w+://|www\.|WWW\.)[a-zA-Z0-9\.\@:-]+[^\"\'>< \r\t\n]*)] {
local $_ = $1;
my $scheme = $2;
s/// if (my $trailing) = /([.,!?()\[\]]+$)/;
s/&(?!\x23?\w+;)/&/g;
s/\"/"/g;
my $href = ($scheme =~ /www\./i ? "http://$_" : $_);
qq{<a href="$href" target="_blank">$_</a>$trailing};
}eg;
is what I use.
Juerd
# { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }
| [reply] [d/l] |
| [reply] |
The NelliePen Society
J.P. Snodgrass. President.
To whom it may concern.
We wish to protest in the strongest terms, this flagrant, un-called for, and clearly prejudicial use of supposedly humourous analogies with total disregard for those ....
"Come back Nellie.....what is the matte....".
"Ellie? Ellie! You didn't let Nellie have the left over spinach did you?........."
"Oh dear"..
Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
| [reply] |
If capturing the link text after finding it so you can use it with the a method in CGI, then just use capturing parentheses in the regex.
$_ = 'some text http://moo.com fish';
/(http:\/\/)/
$href = $1;
For each pair of capturing parentheses (up to nine total), the text they capture is put into $1 through $9. Read perldoc perlre for more information about this and other regex stuff.
Of course, I'd recommend using some of the excellant solutions in this thread, but this is up to you. | [reply] [d/l] [select] |
How are you having trouble converting it using CGI? Please exlain further. You could also post a piece of code to make the problem clear. | [reply] |