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

The stripped down test below runs file as "perl hello.pl", but fails within a PAR created exe.
Anyone know what to do?
C:\>perl hello.pl
I can see C:\temp\foo.txt
Hello

C:\>pp -o hello.exe hello.pl

C:\>hello
I can see C:\temp\foo.txt
12: Cannot open C:\temp\foo.txt
:No such file or directory:
Hello
#!/usr/bin/perl -w use File::Spec; use utf8; my $infile = File::Spec->catfile("C:/temp/", "foo.txt",); if (-e($infile)) { print ("I can see $infile\n"); # Works fine --> if (!(open my $in_fh, "<$infile")) { if (!(open my $in_fh, "<:encoding(utf8)", "$infile")) { my $message = __LINE__.": Cannot open $infile\n:$!:\n"; print ($message); } } else { print ("No in file $infile\n"); } print ("Hello\n");

Replies are listed 'Best First'.
Re: PAR will not play nice with opening encoding(utf8)
by lamprecht (Friar) on May 24, 2010 at 19:05 UTC
    Hi,

    try adding  use encoding 'utf8'; to your code.

    Cheers, Christoph
      That was it. Thanks.
Re: PAR will not play nice with opening encoding(utf8)
by Anonymous Monk on May 25, 2010 at 08:33 UTC
    I think you've found a perl bug, if PerlIO::encoding is missing, open with encoding will fail with no indication this is the problem. You should submit a report :)
    #!/usr/bin/perl -- { # you get no indication that the problem is that PerlIO/encoding.pm # is missing, same when you rename PerlIO/encoding.pm $INC{'PerlIO/encoding.pm'}=__FILE__; open my($in), '<:encoding(utf8)', __FILE__ or die int($!)," $!\n",int($^E)," $^E "; close $in; }