almr has asked for the wisdom of the Perl Monks concerning the following question:
# x.pl use v5.28; use Data::HexDump; use Encode qw(encode decode); my $a0 = $ARGV[0]; my $a0d = decode( q(UTF-8), $a0 ); say HexDump($a0); say HexDump($a0d); open my $fh, q(>), $a0; open my $fhd, q(>), $a0d; sleep 99; # shell aa=$(perl -CSDA -we 'print 1 . chr(0xb1) . chr(0x155) . 2') perl -w x.pl "$aa" & ls -rt xxd /proc/`pidof perl`/cmdline
This also creates a file (or two) with a "funny" name.
Now, on my particular system, it seems that perl starts with a UTF-8 encoding of "$aa" in its /proc/cmdline (i.e. the C "char *argv[]"), and that Perl @ARGV corresponds verbatim to C argv[].
It also seems that for open(), both byte-array strings, and also strings with one unicode codepoint / char (as obtained via decode) create the same filename. Maybe Perl does an implicit utf8 decode()?
But this is just an experiment on a particular setup. I'm not really sure (1) what Perl actually does on startup (does it process its C argv, maybe according to locale), (2) what open() is supposed to take, and (3) what readlink(), readdir() etc are supposed to return. What are the rules?
EDIT: fixed second perl invocation
|
---|