in reply to Re: opening accented file names
in thread opening accented file names

Nice++ But I think that you are confusing things by mentioning chcp. It isn't necessary, at least for this particular accented character (which I typed manually using alt-graph-o in each case shown):

c:\test>dir ac*/b File Not Found c:\test>chcp 850 & echo this is acentó.dat >acentó.dat & perl -we"open I,$ARGV[0]; print while<I>" acentó.dat & del a +c* Active code page: 850 this is acentó.dat c:\test>chcp 437 & echo this is acentó.dat >acentó.dat & perl -we"open I,$ARGV[0]; print while<I>" acentó.dat & del ac* Active code page: 437 this is acentó.dat c:\test>chcp 1250 & echo this is acentó.dat >acentó.dat & perl -we"open I,$ARGV[0]; print while<I>" acentó.dat & del a +c* Active code page: 1250 this is acent&#728;.dat c:\test>chcp 1252 & echo this is acentó.dat >acentó.dat & perl -we"open I,$ARGV[0]; print while<I>" acentó.dat & del a +c* Active code page: 1252 this is acentó.dat

Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
"Science is about questioning the status quo. Questioning authority".
In the absence of evidence, opinion is indistinguishable from prejudice.
RIP an inspiration; A true Folk's Guy

Replies are listed 'Best First'.
Re^3: opening accented file names
by Jim (Curate) on Nov 12, 2010 at 01:00 UTC

    I included the CHCP command in my post because the active code page matters. It governs what is displayed and, in the case of code page 65001, even how commands work (or don't work).

    Here's as faithful as possible on PerlMonks a representation of exactly what I see on my screen as I type these commands at the Windows Command Prompt:

    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:\>chcp 437 Active code page: 437 D:\>perl test.pl acentó.dat
    Successfully opened file 'acent≤.dat'
    D:\>chcp 850 Active code page: 850 D:\>perl test.pl acentó.dat Successfully opened file 'acentľ.dat' D:\>chcp 65001 Active code page: 65001 D:\>perl test.pl acentó.dat Successfully opened file 'acent.dat' D:\>type test.pl #!perl use strict; use warnings; my $fn = shift @ARGV; if (open my $fh, '<', $fn) { print "Successfully opened file '$fn'\n"; close $fh; } else { print "Error opening file '$fn': $!\n"; } D:\>

    (Sorry, I can't follow your session log because there are too many things going on in it at once. It's too dense and complicated.)

      (Sorry, I can't follow your session log because there are too many things going on in it at once. It's too dense and complicated.)

      Sorry, let me simplify it.

      This is in a completely new session as identified by the banner at the top. Everything you see in the session was typed manually, not copy&pasted. (This is important!). As I stated above, I am typing the 'ó' using AltGr-o:

      Microsoft Windows [Version 6.0.6001] Copyright (c) 2006 Microsoft Corporation. All rights reserved. c:\>dir ac*/b File Not Found c:\>chcp 65001 Active code page: 65001 c:\>echo this is the contents of acentó.dat >acentó.dat c:\>dir ac*/b acentó.dat c:\>perl -pe1 acentó.dat this is the contents of acentó.dat c:\>

      The reason typing rather than cutting and pasting is important, is because the character code that sits behind the ó glyph will vary from codepage to code page.

      Hence, note the glyph displayed when the contents of a file created under cp437 are displayed under cp65001. On screen, prior to cutting and pasting to perlmonks, that � character is displayed as the typical 'open box' glyph.

      c:\>chcp 437 Active code page: 437 c:\>echo this is the contents of acentó.dat > acentó.dat c:\>dir /b ac* acentó.dat c:\>perl -pe1 acentó.dat this is the contents of acentó.dat c:\>chcp 65001 Active code page: 65001 c:\>dir /b ac* acentó.dat c:\>perl -pe1 acentó.dat this is the contents of acent&#65533;.dat

      So, your inclusion of the codepages confuses rather than clarifies.


      Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
      "Science is about questioning the status quo. Questioning authority".
      In the absence of evidence, opinion is indistinguishable from prejudice.

        You're mistaken. My inclusion of the CHCP command was essential to understanding that the glyph displayed in the Windows Command Prompt is dependent on the active code page. It is, I assure you. (And I've proved it already.) That's really all there is to it.

        Your attempts to confuse matters with what's inside the file are meaningless and confusing here. We're examining the file name, not the file contents, and what happens when ActivePerl reads the file name.