Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

Would anyone please answer my queries regarding literal "$". How can we use $$ in string replacement?

Replies are listed 'Best First'.
Re: Literal "$"
by graff (Chancellor) on Feb 08, 2011 at 03:39 UTC
    Inside a double-quoted string, put a back-slash in front of "$" to get a literal dollar-sign:
    print "A sample dollar amount: \$12.34\n";
    Or, simply use single-quotes, and don't use a back-slash:
    print 'Another dollar amount: $56.78', "\n";
    Or use the q// quoting operator, which works like single-quotes:
    print q/Yet another amount: $90.12/, "\n";
    There's a whole section in the perlop man page titled "Quote and Quote-like operators." That's something you'll want to read.
Re: Literal "$"
by CountZero (Bishop) on Feb 08, 2011 at 07:28 UTC
    use Modern::Perl; my $dollars= 'I have $10.'; say $dollars; $dollars =~ s/\$/€/; say "Now $dollars";
    Output:
    I have $10. Now I have €10.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James