Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

How to print the dollar sign.

by nasa (Beadle)
on May 09, 2003 at 09:14 UTC ( [id://256798]=perlquestion: print w/replies, xml ) Need Help??

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

How to simply print the $ sign.

print "$";
Nope that didnt work.
print "'$'";
Nope that didnt work.
print "$/";
Nope that didnt work either.

OK what`s the trick.

Nasa.

Replies are listed 'Best First'.
Re: How to print the dollor sign.
by valdez (Monsignor) on May 09, 2003 at 09:24 UTC

    print '$';
    print "\$";.

    Ciao, Valerio

      As an explanation of why it works:

      1. A string enclosed in '' will not be interpolated (ie. any variable names inside will stay what they are instead of being replaced by the value of the variable).

      2. You can use backslashes to "escape" characters, ie. make them lose their special function.

      Example:

      my $var = "Testing 1 2 3"; my $no_interpolation = 'Var = $var'; # result: Var = $var my $interpolate = "Var = $var" # result: Var = Testing 1 2 3 my $escape = "Get lots of \$\$\$ by pressing Shift+4 many times \%-)"; # result: Get lots of $$$ by pressing Shift+4 many times %-) # (note: this money-making technique is designed for German keyboards +:) )
Re: How to print the dollor sign.
by virtualsue (Vicar) on May 09, 2003 at 09:57 UTC
    The trick is explained in perldoc perlop, in the "Quote and Quote-like Operators" section. You need to use non-interpolating quotes, or escape the $ properly (\$, not $/). Per perldoc perlvar, $/ contains the input record separator (newline by default).
Re: How to print the dollor sign.
by PetaMem (Priest) on May 09, 2003 at 09:51 UTC
    As there's FMTOWTDI I couldn't resist:

    print chr(36); print chr(ord('$')); print chr(ord(chr(ord('$')))); # ad infinitum...;-) print "\x{024}";
    I believe on a printer a print "S\x{08}|"; should work also.

    Bye
     PetaMem

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others exploiting the Monastery: (6)
As of 2024-04-23 14:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found