in reply to qr and substitution
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 likesub foo { my ($massage) = @_; local $_ = get_data_from_some_source(); $massage->(); } foo(sub { s/(foo|bar|baz)/\U$1/g });
You must trust the passed arguments in either case (both the closure as well as the string expr passed could do anything).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');
Makeshifts last the longest.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: qr and substitution
by jplindstrom (Monsignor) on Oct 13, 2003 at 20:07 UTC |