There's more than one way to do things | |
PerlMonks |
Modifying muliple matched strings in textby nysus (Parson) |
on Jul 12, 2020 at 12:18 UTC ( [id://11119206]=perlquestion: print w/replies, xml ) | Need Help?? |
nysus has asked for the wisdom of the Perl Monks concerning the following question: In the following piece of markdown text, I want to replace the spaces with a hyphen and also make the link absolute with a slash in front. So I want to go from:
to:
So this is as far as I got and I'm stymied:
The obvious problem with this code is that only the first link gets the space replaced:
I'm drawing a blank on how I might loop through all matches to links and modify those matches. Or maybe there is an entirely better way of pulling this off. Thanks! UPDATE: OK, I noodled around with this some more. On a lark, I tried a "global" match (which I didn't know existed outside substitution), and came up with this:
Though it seems to work, I have a hunch this isn't ideal.
$PM = "Perl Monk's";
Back to
Seekers of Perl Wisdom
|
|