in reply to Re^2: Perl TK character disappearingue
in thread Perl TK character disappearing

Hi, I hit a temporary glitch, then this started working for me. I don't know what to tell you. I suspect you have file encoding mismatches somewhere. When I download your code example, the œ dosn't show up in my editor or Tk. I then manually copy&pasted in œ from your html into the Tk program and it ran. Maybe some unicode guru knows the reason?
#!/usr/bin/perl use warnings; use strict; use Tk; use Tk::TextUndo; use utf8; my $main = MainWindow->new; my $middle = $main->Frame(-borderwidth=>2,-relief=>'groove')->grid(-ro +w=>0,-column=>1,-sticky=>'nsew'); my $middlebox = $middle->TextUndo ( -font => 'arial 20', -wrap => 'word', -spacing2 => 10, -spacing3 => 30, -takefocus => 1, -background => 'white', -width => 70, -height => 10, )->grid(-row=>0, -column=>0, -sticky=>'nsew +'); $middlebox->insert('end',"This is a test of the œ character\n"); print ord('œ'),"\n"; # prints 339 print chr(339),"\n"; $middlebox->insert('end', ord('œ') ); $middlebox->insert('end',"\n"); $middlebox->insert('end', chr(339) ); MainLoop;

I'm not really a human, but I play one on earth.
Old Perl Programmer Haiku ................... flash japh

Replies are listed 'Best First'.
Re^4: Perl TK character disappearingue
by Anonymous Monk on Jun 27, 2012 at 17:32 UTC

    Well, you don't get utf from perlmonks, you get latin-1 or some such, and œ comes back as hex 9C

    If you add use utf8; at the bottom of the program it won't display right :) you have to add it to the top

      That explains the weirdness I saw, but how would you suggest the OP solve the original problem? Also, do you mean that "use utf8" must be listed first in the "use" list?

      I'm not really a human, but I play one on earth.
      Old Perl Programmer Haiku ................... flash japh

        That explains the weirdness I saw, but how would you suggest the OP solve the original problem?

        How I did it :)

        wget -O junk ?abspart=1;displaytype=displaycode;node_id=978515;part=1

        iconv -f windows-1252 -t UTF-8 < junk > pm978515.pl

        Then add  use utf8; at the top of the file pm978515.pl

        Also, do you mean that "use utf8" must be listed first in the "use" list?

        If you add "use utf8;" after  $middlebox->insert('end',"This is a test of the œ character"); it won't work, the string won't be displayed properly because it won't be marked/decoded as utf

Re^4: Perl TK character disappearingue
by cr8josh (Sexton) on Jun 27, 2012 at 22:37 UTC

    Very odd...I pasted your code in from the web, ran, and I get this output:

    This is a test of the 0 œ

    ...and the following errors in my command window...

    Malformed UTF-8 error...(2 times, lines 24 and 26) Wide character in print at....line 27 Malformed UTF-8 error...at line 29

    I'm wondering if this is getting down to different systems...I'm on Windows 7...