in reply to £ symbols

why is it when i print a £(pound) symbol out in perl it comes out as a ? (question mark)?

The answer depends on a lot of things. Since you're using macosx, I'll assume you're using the nifty Terminal app, with the character set encoding configured to the default (utf8 -- if you check the "Window preferences / Display" menu, you can change that setting, e.g. to "ISO Latin 1", if you want to).

If your terminal window is using utf8, then you should see a £(pound) symbol rather than a question mark if you do this:

binmode STDOUT, ":utf8"; print "Here is the pound sign: \xA3\n";
If your text containing the pound sign is coming from some external source, then you have to know what encoding is being used by that source -- then either convert it to utf8, or not, but make sure that the character encoding of the agrees with that of the output file handle.

If you don't want to set STDOUT to utf8 like that, then you'll probably want to set your terminal to use ISO Latin 1 (as explained above).

If the output file handle has not been set to utf8 mode, then byte/character values in the range 128-255 (0x80-0xff) will be output as-is without conversion to utf8 encoding, and in that case, you just want to be sure that the whatever uses that output knows to expect non-utf8 data.

But if you want ut8 output, you have to tell perl that the file handle is supposed to do that (using binmode).

(updated to finish the paragraph that followed the code snippet).

Replies are listed 'Best First'.
Re^2: £ symbols
by Yoda_Oz (Sexton) on Jan 11, 2007 at 23:20 UTC
    my terminal is set to utf8 and when i type in a pound sign it get "\302\243".

    i cant actually get the terminal to display a £ sign no matter what encoding!
      Geez. You are using "Terminal.app", right? What font are you using? I use Monaco, and I see the £ symbol just fine. In case it helps, here are what I guess would be the relevant shell environment variables -- if you type "env" as a command, you should see similar things (I don't actually know what TERM_PROGRAM_VERSION and __CF_USER_TEXT_ENCODING are about):
      $ env TERM_PROGRAM=Apple_Terminal TERM=xterm-color SHELL=/bin/bash TERM_PROGRAM_VERSION=133 __CF_USER_TEXT_ENCODING=0x3B28:0:0 ... $ perl -v This is perl, v5.8.6 built for darwin-thread-multi-2level (with 3 registered patches, see perl -V for more detail) ... $ perl -e 'binmode STDOUT,":utf8"; print "sign: \xa3\n"' sign: £
      The fact that you're seeing just the escaped-octal-digit rendition of the byte values suggests that it's not strictly a perl problem.