in reply to Drop in regex replacements?
Rather than explain the following snippet should give you an idea of what I'm trying to do. I just can't quite get it going and respectfully ask for the help of the monks.Rather than explain it, here is my incomplete and untested (for lack of test data) solution:
Hope this helps :-)sub replace { my ($tag,$attr,$content) = @_; $attr ||= $content; if ($tag eq 'b') { return "<b>$content</b>"; } elsif ($tag eq 'url') { return "<a href='$attr'>$content</a>"; } # etc. etc. etc. } s/\[(\w+)=?(\w*)\](\w+)\[\1\]/replace($1,$2,$3)/esg;
Update:
Ok, let's explain it a little anyway: I've turned your problem inside out, so you only need 1 regex and only 1 s statement. This has 3 advantages:
-- Joost downtime n. The period during which a system is error-free and immune from user input.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Drop in regex replacements?
by IOrdy (Friar) on Sep 09, 2002 at 14:58 UTC | |
by Joost (Canon) on Sep 09, 2002 at 15:07 UTC |