Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Perl seems to mistreat "PerlIO" environment variable (Windows)

by vr (Curate)
on Apr 02, 2020 at 22:27 UTC ( [id://11114964]=perlquestion: print w/replies, xml ) Need Help??

vr has asked for the wisdom of the Perl Monks concerning the following question:

Instead of poking inside source of some App::* CPAN distribution, I tried to fix app's binary STDOUT output (prevent lf to crlf conversion) using said variable, here's SSCCE:

@echo off set PERLIO= perl -E "print qq(\n)" >> tmp perl -E "binmode STDOUT; print qq(\n)" >> tmp set PERLIO=:raw perl -E "print qq(\n)" >> tmp perl -E "binmode STDOUT; print qq(\n)" >> tmp set PERLIO=:raw:crlf:pop perl -E "print qq(\n)" >> tmp perl -E "binmode STDOUT; print qq(\n)" >> tmp perl -E "binmode STDOUT, ':crlf'; print qq(\n)" >> tmp set PERLIO= perl -Mopen=IO,raw -E "say unpack 'H*', $_ while <ARGV>" tmp del tmp

output:

0d0a 0a 0d0a 0d0a 0a 0a 0d0a

Line 3 seems to indicate that

The list becomes the default for all Perl's IO

(quote from link above) doesn't work; line 4 is weird -- IO is now broken and unfixable; further lines demonstrate working and toggleable solution (including from the same perl line/script, not shown above), using strange sandwiches -- :raw:crlf:raw works, too. Looks like a bug to me, maybe not urgent (was it always there?), let it be documented, TWIMC.

Replies are listed 'Best First'.
Re: Perl seems to mistreat "PerlIO" environment variable (Windows)
by haukex (Archbishop) on Apr 03, 2020 at 07:16 UTC

    I updated your code to the following, and added the output I got as comments after every command (Win 10, Perl 5.28).

    In a bug I reported a while back, I got this explanation in regards to the :crlf layer on Windows:

    :crlf is not just a translation layer on top of the buffering system, it's an alternative buffering system that will optionally do the translation. Calling binmode will disable that translation but not the layer. For extra confusion, on Linux binmode will pop off the crlf layer, because it's not presumed to be the only buffering layer.

    What I think this means is that anytime the :crlf layer is missing on Windows, the behavior may be wonky. This appears to be triggered by PERLIO=:raw, and may very well be a bug. Is there any way you can avoid that environment variable being set and only use binmode?

      Is there any way you can avoid that environment variable being set and only use binmode?

      Yes, sure, it's just that it's distribution of App::* variety, end-user targeted, like "no serviceable parts inside", etc. Of course I can fix it (and should notify the author). Thanks for reminding about crlf being "alternative buffering" and therefore operating on raw bytes:

      open my $fh, '>', 'tmp.txt'; binmode $fh, ':encoding(UTF16)'; print $fh qq(\N{U+010A}\n); close $fh;

      output is invalid on Windows (fe ff 01 0d 0a 00 0d 0a). Should have used ':raw:encoding(UTF16)'. Oh, as I see prepending ':raw' regardless is a good practice since long ago, should have paid closer attention to such details.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: perlquestion [id://11114964]
Approved by GrandFather
Front-paged by Corion
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2024-04-16 19:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found