in reply to Re: How to replace '$' in strings
in thread How to replace '$' in strings

alternative regex delimiter can prevent also strange syndrome..
perl -e "print $ARGV[0]=~s{\$}{\\\$}r" a$dollar a\$dollar or perl -e "print $ARGV[0]=~s{([\$\@\%])}{\\\1}gr" a$dollar@rray%%hashes a\$dollar\@rray\%\%hashes


L*
There are no rules, there are no thumbs..
Reinvent the wheel, then learn The Wheel; may be one day you reinvent one of THE WHEELS.

Replies are listed 'Best First'.
Re^3: How to replace '$' in strings
by Athanasius (Archbishop) on Dec 14, 2015 at 13:18 UTC

    Even simpler: use the special regex delimiter ' (single quote) to suppress interpolation:

    #! perl use strict; use warnings; my $string = 'i am us$ing moni$ka expressi$on'; $string =~ s'\$'\$'g; print $string, "\n";

    Output:

    23:12 >perl 1483_SoPW.pl i am us\$ing moni\$ka expressi\$on 23:14 >

    Hope that helps,

    Athanasius <°(((><contra mundum Iustus alius egestas vitae, eros Piratica,

      special regex delimiter ' (single quote) to suppress Interpolation

      Thanks for the tip, nice to learn something new(*).

      For others: This is not in perlre, but under Regexp Quote Like Operators in perlop.

      (*) "new" to me, of course :-)