in reply to opening accented file names

If you have the wide chars in your actual code, you should probably include use utf8. Untested, but it might be enough here.

Replies are listed 'Best First'.
Re^2: opening accented file names
by elef (Friar) on Nov 11, 2010 at 20:51 UTC
    IIRC use utf8 worked for me.
    However, it only works if the filename is hardcoded into the script. If it's typed in by the user, it gets trickier (so much so that I have no solution for that scenario).

      Here, the file name is input by the user as a command-line argument ($ARGV[0]).

      D:\>chcp 1252 Active code page: 1252 D:\>dir acentó.dat /b acentó.dat D:\>perl test.pl acentó.dat Successfully opened file 'acentó.dat' D:\>type test.pl #!perl use strict; use warnings; my $fn = shift; if (open my $fh, '<', $fn) { print "Successfully opened file '$fn'\n"; close $fh; } else { print "Error opening file '$fn': $!\n"; } D:\>
        Fine, but if you have the user provide the filename at runtime, all goes to hell.
        use strict; use warnings; my $fn; print "\nType filename.\n"; chomp ($fn = <STDIN>); print "\nOpening file named $fn\n"; if (open my $fh, '<', $fn) { print "Successfully opened file '$fn'\n"; close $fh; } else { print "Error opening file '$fn': $!\n"; }
        This works for me on WinXP with ActivePerl on a file named i.txt, but it fails if the file is called í.txt.
        I'm sure it has to do with the encoding used by the console, but I'm not sure how to make it just work (TM) on any windows computer.
        Here's a thread in which I asked about the problem - with no final answer, at least no simple and full solution: http://www.perlmonks.org/?node_id=859764