http://www.perlmonks.org?node_id=991643


in reply to How to print a Euro symbol (€) in a PerlTk Label widget.

If the answers above confuse you, what's going on is that the first one has this:

perl -MTk -e "tkinit->Label( -text => qq{\x{20AC}} )->pack; MainLoop;"

For that, we use \x{20AC}, the UTF-8 code for the Euro symbol and, sure enough, on my box, it displays a Label with the Euro symbol.

In the second example, the author suggests using the utf8 pragma. That's because this:

perl -MTk -e "tkinit->Label( -text => qq{€} )->pack; MainLoop;"

... will probably show a Label with a bunch of funny characters because Perl doesn't realize that the € symbol is a UTF-8 character, but interprets it as a byte string. The utf8 pragma tells perl (the interpreter) that your Perl (source code) is written in UTF-8 and it should show up correctly with this:

perl -MTk -e "use utf8; tkinit->Label( -text => qq{€} )->pack; MainLoop;"

However, you've mentioned that you've tried both methods and they've failed to work. This implies that something else is diddling your input and output. Have you tried looking for anything else that is messing with your encodings? You could also check to see if your PERL_UNICODE environment variable has been set to something you don't expact.

You could also try utf8::all, a pragma that tries to convert all input and output to UTF-8, including noting that your source code is also UTF-8 (though this is a blunt instrument which might have side-effects if you're messing with your encodings). If you do this and you use autodie, make sure that you use at least version 2.12 of the latter as earlier versions break utf8::all.