in reply to Re: problem with perl 5
in thread problem with regex in perl script intended for 5.20,but while running on 5.10

ok then what could be the solution in 5.10 ,how can replicate the same behaviour in 5.10,please help me out

Replies are listed 'Best First'.
Re^3: problem with perl 5
by Anonymous Monk on Mar 09, 2015 at 09:03 UTC

    It sounds like you've already solved the problem, but for the benefit of others: The /r modifier causes the expression $string=~s/\Q$oldstring\E/$newstring/gsr to return the modified version of $string without changing the content of $string. However, since then you're just assigning that value back to $string, the expression if ($string = $string=~s/\Q$oldstring\E/$newstring/gsr) is equivalent to if ($string=~s/\Q$oldstring\E/$newstring/gs), since without /r, the $string=~s///; expression modifies $string directly.

Re^3: problem with perl 5
by Anonymous Monk on Mar 09, 2015 at 09:41 UTC

    If you want to have the result in a second string you have to copy the input first.

    my $output = $input; $output = s/\Q$oldstring\E/$newstring/gs;

      Not quite, that second = should be a =~, and the shorter (more idiomatic, I'd say) way to write that is:

      (my $output = $string) =~ s/\Q$oldstring\E/$newstring/gs;