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).


In reply to Re: £ symbols by graff
in thread £ symbols by Yoda_Oz

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.