in reply to Matching non-ASCII file contents with file name.
By having use utf8; in your code, you only tell Perl that your source code is in UTF-8 (so the inverted question mark gets recognized as that), not what the input and output should be encoded in. Perl knows that your output handle is (say) Latin-1 and as it can convert the Unicode string it read from the UTF-8 to Latin-1 it does so when printing.
I find the approach of explicitly specifying the encodings for filenames the easiest way to get consistent results:
#!perl use strict; use warnings; use charnames ':full'; binmode STDOUT, ':encoding(UTF-8)'; print "\N{INVERTED QUESTION MARK}\n"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Matching non-ASCII file contents with file name.
by mldvx4 (Hermit) on Dec 23, 2022 at 06:39 UTC | |
by Corion (Patriarch) on Dec 23, 2022 at 07:16 UTC | |
by hippo (Archbishop) on Dec 23, 2022 at 08:26 UTC |