|
|
| Just another Perl shrine | |
| PerlMonks |
Re: multiple substitutionsby IndyZ (Friar) |
| on Apr 10, 2002 at 01:12 UTC ( [id://157959]=note: print w/replies, xml ) | Need Help?? |
This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.
Try the global match (g) and eval (e) flags. Here's an example:
The first part is obvious: It matches 1 or more capital characters in the range A-Z, and grabs it to $1. The 'e' flag on the regexp causes the the 'reverse($1)' to be eval'd and the return value to be substituted in, and the 'g' flag makes as many matches as possible. This particular example reverses any and all sections of capital letters so "LREP java PYTHON" would become "PERL java NOHTYP". Instead of using the reverse function, write your own function to do the database access, pass it the matched data and have it return what should be substituted in. Just a warning: I haven't run any benchmarks or anything, but this will probably cause a pretty big speed hit since you are running an eval() on every match.
Update:
Yet Another Update:
In Section
Seekers of Perl Wisdom
|
|
||||||||||||||||||||||||||||||