in reply to Re: Substituting in the substitution!
in thread Substituting in the substitution!

I didn't explain myself quite right.

The "/" can be in any part of the string, so a new regexp won't fix it. What I want is to capture four clusters and then, when substituting, replace the "/" inside the clusters.

Right now, I did this:
$do_the_change_mon = sub { $thingy = shift; $thingy =~ tr|/|_|; return $thingy; } $expr = s| \[([A-Z/]+)\s([A-Z/]+)\s([A-Z/]+)\s([A-Z/]+)\s\] |&$do_the_change_mon("$1_$2_$3_$4)|xe;

Thank you all for your kind answers, monks!

Replies are listed 'Best First'.
Re: Re: Re: Substituting in the substitution!
by diotalevi (Canon) on May 06, 2004 at 17:57 UTC

    That's not bad. Consider this. I rolled your A-Z/ loop up and then did the substitution on a copy inside the RHS.

    $expr =~ s(\[((?:[A-Z/]+)\s){4,4})\]){ my $match = $_; $match =~ s([/\s])(_)g; $match; }ge;