Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical
 
PerlMonks  

Re^2: Native newline encoding

by sauoq (Abbot)
on May 22, 2012 at 17:59 UTC ( #971842=note: print w/ replies, xml ) Need Help??


in reply to Re: Native newline encoding
in thread Native newline encoding

I don't think that really addresses the issue.

One way to get what he wants would be to write "\n" to a file and then open that file, use binmode(), and then slurp it in and see what you get. It should be, for example, 0d0a on Windows and 0a on *nix.

I have an inkling that it won't work that way with an in memory file...

I don't really do Windows but I can check it on a machine with Strawberry Perl later.

-sauoq
"My two cents aren't worth a dime.";


Comment on Re^2: Native newline encoding
Select or Download Code
Re^3: Native newline encoding
by BrowserUk (Pope) on May 22, 2012 at 18:10 UTC
    It should be, for example, 0d0a on Windows ... I don't really do Windows

    That's a bit obvious :)

    It isn't perl(*) that writes the extra character; it is the C runtime (when writing to a data file opened as text). Those extra characters are also stripped by the CRT when reading -- assuming text mode.

    If Perl added them itself, then the CRT would also do it and you'd end up with a real mess.

    perl; and Perl programmers shouldn't need to concern themselves with the details, because -- unless they are reading text files in bin mode; which they shouldn't be -- the addition and removal of the 'extra characters' should be entirely transparent.

    (*) ignoring PerlIO which does; but only because it bypasses the CRT and then emulates it -- the point of which mystifies me, but there it is.


    With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
    Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
    "Science is about questioning the status quo. Questioning authority".
    In the absence of evidence, opinion is indistinguishable from prejudice.

    The start of some sanity?

      That's a bit obvious :)

      Erm... what's the obvious part? That I don't do Windows or that it should be 0d0a? Or both?

      He asked for the "native newline encoding of the OS"... It doesn't matter what writes it. Maybe it's because I don't do Windows but do have to deal the bastardized text files that come from Windows that the distinction is meaningless. I know I don't care whether it is Perl or the run time writing the characters. That they are there is what matters.

      -sauoq
      "My two cents aren't worth a dime.";
        He asked for the "native newline encoding of the OS"... It doesn't matter what writes it.

        Sorry mate! But it absolutely does matter.

        Which is why my post contains two questions which salva will get around to answering (or not) in his own time.


        With the rise and rise of 'Social' network sites: 'Computers are making people easier to use everyday'
        Examine what is said, not who speaks -- Silence betokens consent -- Love the truth but pardon error.
        "Science is about questioning the status quo. Questioning authority".
        In the absence of evidence, opinion is indistinguishable from prejudice.

        The start of some sanity?

      Also, there are more OS's than *nix and Windows to worry about.

      -sauoq
      "My two cents aren't worth a dime.";
      It isn't perl(*) that writes the extra character;

      (*) ignoring PerlIO which does;

      So, as nearly every modern perl out there has been built with PerlIO, your first statement is either talking about those ~0.01 percent which haven't, or you're saying that PerlIO doesn't belong to perl ... both of which seem pretty nonsensical to me.

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others about the Monastery: (9)
As of 2014-08-22 14:47 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (158 votes), past polls