in reply to Malformed UTF-8 character

Is your file stored in UTF-8?

0xb0 is the representation of the degree symbol in Latin-1, but you told perl that your source file is UTF-8. Converting it to actually be UTF-8 should help.

Replies are listed 'Best First'.
Re^2: Malformed UTF-8 character
by Steve_BZ (Chaplain) on Apr 30, 2011 at 13:28 UTC

    Thanks for this. What do you mean by actually convert it. And how can I tell if it's in UTF-8 or not. Does

    use utf8; binmode STDOUT, ":utf8"; use open ':encoding(utf8)';

    not do it?

    Do you mean what eff_i_g says and put that extra character (Â) in so the function would read t("°C")?

    Sorry, I'm away from my PC at the moment or I'd test it myself.

    Regards

    Steve.

      It seems you don't really understand character encodings. Try reading this article get the basics.

      The line use utf8; tells Perl that your script is stored in UTF-8, but it is not. Your editor did not save it as UTF-8, but rather as another encoding, likely Latin-1.

      So either don't tell Perl that the file is stored in UTF-8 when it is not, or do store the file in UTF-8 (and use an editor which properly supports UTF-8).

        Hi Moritz,

        I think you're right. I didn't understand, although I'm already following much of the advice in the your article.

        Interestingly, I was already using utf-8 encoding in all my files except this one. I so rarely have to do anything to the filesave default, that I forgot they were there. In fact both the fixes suggested here worked (correcting the file encoding and inserting  in front of the degrees sign).

        Thanks for everything

        Regards

        Steve