If you want the output of a function call as part of the left-side match string in a regex, why not just assign the function output to a scalar, and use the scalar as a match string?
my $match = chr 231;
my $replc = "c";
$text =~ s/$match/$replc/gise;
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...
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.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.