Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Odd encoding problem in Tk app when packaged with pp

by elef (Friar)
on Jan 27, 2013 at 21:20 UTC ( #1015589=perlquestion: print w/ replies, xml ) Need Help??
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

Comment on Odd encoding problem in Tk app when packaged with pp
Select or Download Code
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.
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.

        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

        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.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://1015589]
Approved by ww
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (2)
As of 2014-09-21 01:51 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    How do you remember the number of days in each month?











    Results (165 votes), past polls