Syntactic Confectionery Delight | |
PerlMonks |
Regex Substitution Evaluationsby mobiusinversion (Beadle) |
on Jul 05, 2008 at 19:53 UTC ( [id://695736]=perlquestion: print w/replies, xml ) | Need Help?? |
mobiusinversion has asked for the wisdom of the Perl Monks concerning the following question:
Dearest Monks,
Please consider the following code: I am trying to create a subroutine that consumes a string, a pattern, a replacement and a modifier (perhaps limited to one or more of 'igsx') and returns the result of a substitution: I would like to call such a subroutine as follows: Of course, the above doesn't work. But I have tried many other ways, e.g. using eval, s///ge, s///gee, etc. I have attempted to do my homework using the Owl, Camel and Ram books, plus the perldoc, but I am totally stumped. Any help would be greatly appreciated. Update: 13:06 PST This appears to work: It does however, to my mind, open security problems due to the eval'ing - which I hope is unnecessary with a more elegant solution. Besides security, will this fail on certain edge cases? (besides non-escaped members of the dirty dozen, which I'm handling now)
Back to
Seekers of Perl Wisdom
|
|