in reply to Re^7: Converting Unicode
in thread Converting Unicode
So actually I had forgotten about it, and then when you reminded me I was going to say "oh right, but it doesn't apply to modules, only the main script", and then I gave it a test and actually it works..?
perl -C -E 'use Path::Tiny; say length((path("unicode.txt")->lines)[0])'
but that seems to disagree with the documentation:
The io options mean that any subsequent open() (or similar I/O operations) in main program scope will have the :utf8 PerlIO layer implicitly applied to them, in other words, UTF-8 is expected from any input stream, and UTF-8 is produced to any output stream. This is just the default set via ${^OPEN}, with explicit layers in open() and with binmode() one can manipulate streams as usual. This has no effect on code run in modules.
Though, still, the one thing missing is unicode handling of file names, such as the return values of readdir.
Edit:
So actually the documentation is correct, it only applies to the main module. Path::Tiny is just very smart about doing what you mean, because it calls
my $binmode = $args->{binmode}; $binmode = ( ( caller(0) )[10] || {} )->{'open<'} unless defined $ +binmode; my $fh = $self->filehandle( { locked => 1 }, "<", $binmode );
So, no, -C isn't what I'm talking about. I mean a perl-wide change of defaults that makes all text (non-binmode("raw")) default to decoding UTF-8 in all modules everywhere. ...because that would fix Polyglot's Test::More problem without monkeying around with file handles private within other modules.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^9: Converting Unicode
by LanX (Saint) on Dec 05, 2023 at 15:03 UTC | |
by NERDVANA (Priest) on Dec 05, 2023 at 19:31 UTC | |
by Polyglot (Chaplain) on Dec 06, 2023 at 02:27 UTC | |
by jeffenstein (Hermit) on Dec 06, 2023 at 09:28 UTC | |
by Polyglot (Chaplain) on Dec 06, 2023 at 10:29 UTC | |
|