Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot
 
PerlMonks  

How many defaults of $/ does perl have?

by stevieb (Canon)
on Sep 18, 2015 at 23:15 UTC ( [id://1142473]=perlquestion: print w/replies, xml ) Need Help??

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

Semi-related to CPAN module unit test issues: OS line endings, I'm wondering how many defaults of the Record Separator does Perl use?

I know on installs of *nix (at least the ones I've used) it'll set $/ to "\n" and on Windows it'll be set to "\r\n", but are there any other situations where $/ will be set to something different?

How is perl told what this special variable is? Is it compiled in externally, or can perl tell what kind of system it's being compiled on, and set this default itself?

-stevieb

Replies are listed 'Best First'.
Re: How many defaults of $/ does perl have?
by LanX (Saint) on Sep 18, 2015 at 23:24 UTC

      Understood LanX, on Windows, $/ is set to \r\n by default. I've found that on Windows, you can strip \r and be left with an \n (which is expected). I'm curious to know how, where and why this is compiled in. What's the trigger, and are there other *common* possibilities other than \r\n and \n.

        No its not!

        Read the linked post, the IO layer does the translation.

        Mac OS <10 had only "\r".

        Cheers Rolf
        (addicted to the Perl Programming Language and ☆☆☆☆ :)
        Je suis Charlie!

Re: How many defaults of $/ does perl have?
by Anonymous Monk on Sep 18, 2015 at 23:36 UTC

      perlport Newlines is exactly what I needed to see to start bettering my understanding.

      Thanks, AnonyMonk

        ... to start bettering my understanding.

        If you have access to multiple platforms, a little experimentation can afford insight. Something like Data::Dump::dd can also be helpful. The following is on my Windoze 7 laptop:

        c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "print qq{'x$/y'}; dd $/, $\; " 'x y' ("\n", "\n")

        Update: In the spirit of making sure that what one posts is true, clear and helpful, I thought I'd test my example code with  $/ = "\r\n". The whole idea of the example was that you'd be able to see a difference between "\n" and "\r\n". Not so. Easy to see why when you think about it. I'll have to think of a better example!

        c:\@Work\Perl\monks>perl -wMstrict -MData::Dump -le "print qq{'wx$/yz'}; dd $/; ;; $/ = qq{\r\n}; print qq{'wx$/yz'}; dd $/; " 'wx yz' "\n" 'wx yz' "\r\n"
        (But at least dd does not mislead.)


        Give a man a fish:  <%-{-{-{-<

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others avoiding work at the Monastery: (7)
As of 2024-03-28 15:10 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found