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

elef has asked for the wisdom of the Perl Monks concerning the following question:

Dear monks, this one is a bit unusual: my Tk app handles utf-8 strings entered into a Tk entry box fine, but when the same app is packaged into an exe with pp, some characters are corrupted. Specifically, ű becomes û and ő becomes õ (I hope these show up as intended here). They already show up incorrectly as you type them, and are printed to file incorrectly as well. This occurs both on Win7 and XP.
All other characters I tested are fine, including cyrillic and Arabic ones, but of course that's not entirely reassuring. How likely is it that other characters will also be corrupted? Is there any simple solution I could try? I can work around this with a simple s/û/ű/g but that's no help if many other unknown characters are also corrupted. Is this problem in Tk? pp? Windows?
Interestingly, the two problem characters work fine when pasted into the entry box instead of typing them in.
Here's a short script that exhibits the issue (I imagine you'll have to switch to the Hungarian keyboard layout if you want to test it, given that the problem doesn't occur if you use Ctrl-c Ctrl-v):
use strict; use warnings; use Tk; use utf8; my $mw = Tk::MainWindow->new; $mw->minsize(300, 250); my $entered; my $entry = $mw->Entry( -textvariable => \$entered, -width => 75, -tak +efocus => 1 )->pack(); $entry->focus( -force ); open (OUT, ">>:encoding(UTF-8)", "_entered.txt"); my $go = sub { print OUT "$entered\n"; }; my $buttgo = $mw -> Button( -text=>"Go", -command => $go ) -> pack(); $mw->bind( '<Return>', $go ); my $buttexit = $mw -> Button( -text=>"Exit", -command => sub {exit}, ) -> pack(); Tk::MainLoop();

And here's the exe from the same script: https://www.dropbox.com/s/dyxir5rd4et0fj7/entry.exe

Replies are listed 'Best First'.
Re: Odd encoding problem in Tk app when packaged with pp
by Anonymous Monk on Jan 28, 2013 at 02:00 UTC
      Thank you for that.
      I did not use the -x switch because I assumed that if the .exe created launches and runs without any error messages, then it's fine.
      Anyway, I now ran pp with -x and the problem went away. I can't see this mentioned in the bug reports you linked, so I'm guessing you know this from personal experience...?
      I digged around in the .exe files generated by pp, and found that the MANIFEST files are different. Specifically, the one made with -x contains the following entries, which are missing from the one made without -x:
      lib/Encode/Byte.pm lib/auto/Encode/Byte/Byte.bs lib/auto/Encode/Byte/Byte.dll lib/sitecustomize.pl

      Obviously, this must be the explanation. I guess the lesson is to always use -x.

        Yes, this is why you had the initial problem, pp -x executes the code in an attempt to determine additional run time dependencies. This isn't a bug, it won't be in the reports mentioned, though it's documented in pp. See also PAR::FAQ and PAR::Tutorial.

        I can't see this mentioned in the bug reports you linked, so I'm guessing you know this from personal experience...?

        Yup, 99/100 PAR/pp questions are solved with -x, the rest are solved with -l, the rest are bugs :)

        I linked the first bug reports I could find, didn't seem important to check if they mention pp -x

Re: Odd encoding problem in Tk app when packaged with pp
by Khen1950fx (Canon) on Jan 27, 2013 at 22:32 UTC
    It works for me on Linux:
    #!/usr/bin/perl use strict; use warnings; use Tk; my $mw = Tk::MainWindow->new; $mw->minsize( 300, 250 ); my $entered = "\x{171}"; open OUT, '>>', $entered; binmode OUT, ":encoding(UTF-8)"; my $entry = $mw->Entry( -textvariable => \$entered, -width => 75, -takefocus => 1, )->pack(); $entry->focus( -force ); my $go = sub { print OUT "$entered\n"; }; my $buttgo = $mw->Button( -text => "Go", -command => $go )->pack(); $mw->bind( '<Return>', $go ); my $buttexit = $mw->Button( -text => "Exit", -command => sub { exit }, )->pack(); close OUT; Tk::MainLoop();
      Well, it works for me on Windows, too. I'm only getting a bug when packaging the script with PAR::Packer, and even then only when typing into the box, not when copy-pasting into it or hardcoding the funky characters into the script.