in reply to Re: nested replace
in thread nested replace

Thanks choroba, for your comments of the modifier. I used:

$string =~ s:/ \* (.*?) \*/ : (my $x = $1) =~ s/[^\n]//g; $x :gsex;
but it replaces the text within the "/*...*/" with the a position of the text.
">/*x*/<" is converted in ">1<" instead of "><" ">/*x\nx\nx*/<" is converted in ">3<" instead of ">\n\n<"

Replies are listed 'Best First'.
Re^3: nested replace
by choroba (Cardinal) on Mar 18, 2016 at 10:09 UTC
    Weird, works for me in 5.8.3, 5.10.1, 5.20.1, and 5.22.1.
    $ perl -lwe ' $string = q<a/*z*/b>; $string =~ s: /\* (.*?) \*/ : (my $x = $1) =~ s/[^\n]//g +; $x :gsex; print $string; ' ab
    ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,
Re^3: nested replace
by Anonymous Monk on Mar 18, 2016 at 10:07 UTC

    You probably forgot the final "; $x" in the replacement part of the outer regex. Without it, the inner substitution returns the number of times it matched.

Re^3: nested replace
by Anonymous Monk on Mar 18, 2016 at 10:13 UTC

    Sorry !

    Your code works correct ! Thanks!!

    In my code I did not have the last $x

    $string =~ s:/ \* (.*?) \*/ : (my $x = $1) =~ s/[^\n]//g; $x :gsex; ^^