You have to pass the substitution string separately. If that's really an issue, you might consider passing a closure instead, so that it would read something like:
sub foo {
my ($massage) = @_;
local $_ = get_data_from_some_source();
$massage->();
}
foo(sub { s/(foo|bar|baz)/\U$1/g });
That may or may not work in your case. The problem you'll run into with passing a string is that you can't use the match variables in it and have them interpolated later - you'd have to do something like
sub foo {
my ($rx, $subst_e) = @_;
local $_ = get_data_from_some_source();
s/$rx/eval $subst_e/ge;
# short form:
# s/$rx/$subst_e/gee;
}
foo(qr/(foo|bar|baz)/, '\U$1');
You
must trust the passed arguments in either case (both the closure as well as the string expr passed could do anything).
Makeshifts last the longest.
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.