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

Re^2: symbols

by Thelonius (Priest)
on Jan 11, 2007 at 16:12 UTC ( [id://594190]=note: print w/replies, xml ) Need Help??

in reply to Re: symbols
in thread symbols

In most character sets, including iso-8859-1 and Unicode, the pound symbol is 163 decimal, or 0xA3 hexadecimal, so you should use "chr(163)". If you use the correct encoding on the output, that will be translated to the correct character.

E.g. this

perl -e 'binmode STDOUT, ":encoding(cp437)"; print chr(0xA3), "\n"' \ | od -c -t x1 0000000 234 \r \n 9c 0d 0a
(Code page 437 is a common code page for a DOS box on Windows, but it can be changed with CHCP.)

and this

perl -e 'binmode STDOUT,":encoding(latin-1)"; print chr(0xA3),"\n"' \ | od -c -t x1
0000000 243 \r \n a3 0d 0a

But, note that 156 (0x9c) does not work with the Encode translations:

perl -e 'binmode STDOUT, ":encoding(cp437)"; print chr(0x9C), "\n"' \ | od -c -t x1
"\x{009c}" does not map to cp437. 0000000 \ x { 0 0 9 c } \r \n 5c 78 7b 30 30 39 63 7d 0d 0a

If you are outputting to HTML, you also have to make sure the Content-type charset gets set correctly or output the characters as entities, e.g. £ or £

Log In?

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://594190]
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (2)
As of 2024-06-18 03:40 GMT
Find Nodes?
    Voting Booth?

    No recent polls found

    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.