> I guess the /r switch allows you to do it as it doesn't modify $1. Thanks, good call. I'll check it's supported on my version of perl.
If not try this instead:
my $x = q{Here are [[a variable]] number [[of words]] in brackets};
say $x;
$x =~ s{\[\[(.*?)\]\]}{ (my $x=$1) =~ s/ /_/g; $x }ge;
say $x;
added a /g to allow multiple chunks to be processed.
Here are [[a variable]] number [[of words]] in brackets
Here are a_variable number of_words in brackets
But to improve readability I would rather opt against one-liner and call a function in the replacement part
sub blank2under {
my $x=shift;
$x =~ s/ /_/g;
return $x;
}
update
and here a generic function to simulate /r
sub rx (&$) {
my $c_regex=shift;
local $_=shift;
$c_regex->();
return $_
}
my $x = q{Here are [[a variable]] number [[of words]] in brackets};
print "$x\n";
$x =~ s(\[\[(.*?)\]\])( rx {s/ /_/g} $1 )ge;
print "$x\n";
|