views:

171

answers:

4

alt text

How to display 192 character symbol ( └ ) in perl ?

+10  A: 

What you want is to be able to print unicode, and the answer is in perldoc perluniintro.

You can use \x{nnnn} where n is the hex identifier, or you can do \N{...} with the name:

perl -E 'say "\x{2514}"; use charnames; say "\N{BOX DRAWINGS LIGHT UP AND RIGHT}"'
Daenyth
I have edited the code example to be relevant to the question. If you do not agree, you can easily undo this.
daxim
@daxim: Thanks!
Daenyth
+3  A: 

That looks like the Code page 437 encoding. Perl is probably just outputting bytes that you give it. And your terminal is probably expecting UTF8.

So you need to decode it to Unicode, then re-encode it in UTF-8.

EDIT: Correct encoding.

Douglas Leeder
Or, change your terminal settings. :)
brian d foy
No, it's IBM437. See [IANA](http://www.iana.org/assignments/character-sets), [RFC 1345](http://datatracker.ietf.org/doc/rfc1345/), [en.Wikipedia](http://en.wikipedia.org/wiki/IBM437).
daxim
+8  A: 

To use exactly these codes your terminal must support Code Page 437, which contains frames. Alternatively you can use derived CP850 with less boxing characters. Such boxing characters also exist as Unicode Block Elements. The char which you want in perl is noted as \N{U+2514}. More details in perlunicode

gertas
`"\x{2514}"` does it, too. This syntax is explained in [perlop](http://p3rl.org/op#Quote-and-Quote-like-Operators).
daxim
+2  A: 

As usual, Jon Skeet nails it: the 192 code is in the "extended ASCII" range. I suggest you follow @Douglas Leeder's advice, but I'm not sure which encoding www.LookupTables.com is giving you; ISO-8859-1 thinks 192 maps to "À", and Mac OS Roman thinks its "¿".

Hank Gay
"Extended ASCII" is a family of encodings. The one in the question is IBM437. See [IANA](http://www.iana.org/assignments/character-sets), [RFC 1345](http://datatracker.ietf.org/doc/rfc1345/), [en.Wikipedia](http://en.wikipedia.org/wiki/IBM437).
daxim