Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re^2: CR-LF on UTF-16LE files on Windows

by vitoco (Hermit)
on Nov 07, 2018 at 18:43 UTC ( [id://1225375]=note: print w/replies, xml ) Need Help??


in reply to Re: CR-LF on UTF-16LE files on Windows
in thread CR-LF on UTF-16LE files on Windows

Ok, that worked as expected. I need to read more about layers to fully understand this.

Thanks!

  • Comment on Re^2: CR-LF on UTF-16LE files on Windows

Replies are listed 'Best First'.
Re^3: CR-LF on UTF-16LE files on Windows
by ikegami (Patriarch) on Nov 07, 2018 at 19:18 UTC

    :crlf converts 0D 0A into 0A on read, and it converts 0A into 0D 0A on write. This was being done to the encoded strings when it should have been done to the decoded strings.

    (My earlier post has been edited to integrate this.)

      Would binmode() work? I don't have any files like that at my disposal to test.

        binmode would not work.

        When binmode applies :raw, it disables any existing :crlf layer rather than removing it. And a subsequent :crlf renables the existing :crlf layer rather than adding a new one. That means that

        binmode($fh, ':raw:encoding(UTF-16LE):crlf')

        is no different than

        binmode($fh, ':encoding(UTF-16LE)')

        It's therefore impossible to apply :encoding(UTF-16LE) to STDIN, STDOUT and STDERR on Windows (if you also want to :crlf). You'd need something like the following instead:

        open(my $fh, '<&=:raw:encoding(UTF-16le):crlf', fileno(STDIN)); *STDIN = $fh;

        (Untested)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1225375]
help
Chatterbox?
and the web crawler heard nothing...

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

    No recent polls found