in reply to qr and substitution

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.

Replies are listed 'Best First'.
Re: Re: qr and substitution
by jplindstrom (Monsignor) on Oct 13, 2003 at 20:07 UTC
    For now my immediate need is to just remove anything matched, i.e. do a s/$something_dynamic// . I hoped it would be trivial to do the fancy thing (replace it) but since it isn't, I'll just do the simple thing until I need more.

    Thanks.

    /J