in reply to Function call in a regular expression
The expression content can be as dynamic, flexible and/or complicated as you need it to be -- assign different values to $match on every iteration of some loop, use some kind of data structure (hash, AoA or HoA or whatever) to store pre-computed (or hard-coded) pairings of $match and $replc, and so on. Check out the "qr" operator in "perldoc perlop" for more ideas...my $match = chr 231; my $replc = "c"; $text =~ s/$match/$replc/gise;
The only reason to want function calls in the matching part would be to write more compact code, but "more compact" often means "harder to read/debug/maintain". (I guess another reason to want this would be to write "better" obfus.)
Using executable code in the replacement part is of course a different story -- you can do lots of things with this that would be really hard to do any other way.
|
|---|