Beefy Boxes and Bandwidth Generously Provided by pair Networks
Come for the quick hacks, stay for the epiphanies.
 
PerlMonks  

Re: CR-LF Newlines as 2 distinct characters

by Thelonius (Priest)
on May 19, 2006 at 13:27 UTC ( [id://550491]=note: print w/replies, xml ) Need Help??


in reply to CR-LF Newlines as 2 distinct characters

The encoding is "utf16le", that is "utf16 little endian", which is the standard representation on (little-endian) Windows x86 machines. Unicode include a byte-order mark character just so you can distinguish utf16be from utf16le.

It tried using binmode to see if I could get the :crlf layer to be applied before the encoding layer, but it doesn't work. This seems like something that should be fixed in perl, since Windows is the most commonly used OS in the world, after all.

Anyway, here's how I would do it:

open PLAYLIST, ">", "playlist.plp" or die "Couldn't open playlist.plp: $!\n"; binmode PLAYLIST, ":raw:encoding(utf16le)" or die "binmode: $!\n"; print PLAYLIST "abcd\r\n"; $\ = "\r\n"; print PLAYLIST "efgh";
You can actually combine the binmode options into the open statement like so:
open PLAYLIST, ">:raw:encoding(utf16le)", "playlist.plp" or die "Couldn't open playlist.plp: $!\n"; print PLAYLIST "abcd\r\n"; $\ = "\r\n"; print PLAYLIST "efgh";

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (2)
As of 2024-06-18 01:22 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?
    erzuuli‥ 🛈The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.