Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

How do I escape a "$" in the input stream

by Anonymous Monk
on Sep 10, 2002 at 09:04 UTC ( [id://196587]=perlquestion: print w/replies, xml ) Need Help??

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

Hi

I am a new user here and this is my first posting. I am writing a snippet of code to read an input string from command line. Here is the snippet I use :
$text=$ARGV[0]; print "$text\n";

This reads the value of ARGV[0] into a variable and prints it. If I give it an input of "This is $200", the print out is
"This is 00"

I understand that this happens because perl interprets $2 like a (reg-ex) variable rather than a dollar value (money). Printing $text with a single quote will not interpolate the $text variable.

How can I read a line from input stream with a dollar in it??
Any help is appreciated.
Thanks

Replies are listed 'Best First'.
Re: How do I escape a "$" in the input stream
by projekt21 (Friar) on Sep 10, 2002 at 09:19 UTC

    It's your shell, not perl. Try:

    > echo "This is $200" This is 00 > echo "This is \$200" This is $200 > echo 'This is $200' This is $200

    So use a backslash or single quotes, not doubles.

    alex pleiner <alex@zeitform.de>
    zeitform Internet Dienste

Re: How do I escape a "$" in the input stream
by blm (Hermit) on Sep 10, 2002 at 09:15 UTC
    It looks like the $ sign and the first character are taken by the shell (eg bash) to be a shell variable therefore the $ sign and the first character are not getting into ARGV at all. Try running it with ./program.pl \$200 or ./program.pl "$200"

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://196587]
Approved by grinder
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-04-19 08:04 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found