in reply to Re: utf8::downgrade() and file system operators
in thread utf8::downgrade() and file system operators

Thanks for the sensible suggestion!

I put an SSCCE together, which produces this output with strawberry-perl v5.38.0 under Windows 10 (default file system type, I guess):

perl -w .\TestFileOpsWithUTF8_Names.t 1..2 ok 1 - check -f with non-UTF8 file name not ok 2 - check -f with UTF8 file name # Failed test 'check -f with UTF8 file name' # at .\TestFileOpsWithUTF8_Names.t line 18. # Looks like you failed 1 test of 2.

#!perl use strict; use warnings; use Test::Simple tests => 2; my $fnameNoUTF8 = q{ß}; # some character that is present in Latin1, + but not in ASCII my $fnameUTF8 = $fnameNoUTF8; utf8::upgrade($fnameUTF8); # create an empty file with a NON-ASCII file name open my $fh, q{>}, $fnameNoUTF8 or die "could not create file $fnameNo +UTF8:$!"; close $fh or die "could not close file $fnameNoUTF8"; # test for this file with original name ok( -f $fnameNoUTF8 , "check -f with non-UTF8 file name"); # test for this file with UTF8-upgraded name ok( -f $fnameUTF8 , "check -f with UTF8 file name" ); #cleanup unlink $fnameNoUTF8 or die "could not unlink file $fnameNoUTF8";

Replies are listed 'Best First'.
Re^3: utf8::downgrade() and file system operators
by choroba (Cardinal) on Feb 17, 2024 at 19:13 UTC
    You forgot to create the file with the other name.
    open my $fh2, q{>}, $fnameUTF8 or die "could not create file $fnameUTF +8:$!"; close $fh2 or die "could not close file $fnameUTF8";

    You might want to unlink it at the end, too.

    map{substr$_->[0],$_->[1]||0,1}[\*||{},3],[[]],[ref qr-1,-,-1],[{}],[sub{}^*ARGV,3]