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

Re: (OT) Fixing Line Endings

by Melly (Hermit)
on Nov 30, 2006 at 14:44 UTC ( #586949=note: print w/replies, xml ) Need Help??

in reply to (OT) Fixing Line Endings

Could someone explain to an idiot (e.g. me) how this solves line-ending problems...

Tom Melly,

Replies are listed 'Best First'.
Re^2: (OT) Fixing Line Endings
by davorg (Chancellor) on Nov 30, 2006 at 14:52 UTC

    A Perl program that is created on Windows will have Windows line end characters (i.e. CR/LR or \015\012). If you upload that to a Unix server without translating the line endings then your shebang line will look like this:


    The \n is the line end character for Unix, so that's not a problem. But some Unix shells will look for a program called /usr/bin/perl\r and, usually, won't find it.

    As a couple of us have suggested, adding an option to the shebang line solves the problem as the shebang line will then look like this:

    #!/usr/bin/perl -w\r\n

    The shell parses the command name (/usr/bin/perl) out of that and passes the rest of it (-w\r) to the Perl interpreter as options. Perl is cleverer than the shell and will handle both kinds of line endings.


    "The first rule of Perl club is you do not talk about Perl club."
    -- Chip Salzenberg

      A Perl program that is created on Windows will have Windows line end characters (i.e. CR/LR or \015\012).

      Although, just for informational purposes, it's important to note that you don't have to create files with the \r\n ending. I've been creating all of my files with \n endings for years on Windows, and it's saved me a lot of grief, particularly when ftp-ing files without worrying about setting text mode. The text editors that I've been using are jedit and vim; I'm sure there are others that can do this.

      actually she-bang is a kernel thing you have to fix the broken kernel ...which I would not call un*x

Re^2: (OT) Fixing Line Endings
by jbert (Priest) on Nov 30, 2006 at 14:48 UTC
    The #!...\n line at the beginning of an executable file on a Unix system is recognised as telling the kernel that this is a script, to be passed to the interepreter named in the ... part.

    If the line is '#!/usr/bin/perl\r\n' (as it would be on a Windows box), the kernel will attempt to find a file called '/usr/bin/perl\r'.

    It's a hilarious (but real) solution.

      Ah! Tnx. Hmm... couldn't you create a perl script /usr/bin/perl\\r and have that handle the problem?

      Tom Melly,
        Creating the symlinks is an even lighter-weight way of doing it.
        Hmm... couldn't you create a perl script /usr/bin/perl\\r and have that handle the problem?

        That's essentially what they did. A symbolic link is a UNIX way of saying: "this file is the same as that file over there". They're like Perl references, only for a file system.

        The real problem was getting the symlink command to run from the shell command line: eventually, they gave up, and used perl instead...

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://586949]
[Corion]: Hi Lady_Aleena!
[Lady_Aleena]: marioroy, are you also writing a Meditation for this?
choroba o/
Discipulus adds tozzetti alle mandorle to the platter on the sideboard.
Lady_Aleena was checking #cbstream and saw the big announcement.
[marioroy]: Tie::IxHash can be shared. Also similar modules. I cannot wait to post a solution sharing Tie::File and iterating among workers.
[marioroy]: Lady_Aleena Yes, will post something with all the new features. Parallel with few lines of code.
[marioroy]: Yes, will do for PM. I love PM.
Lady_Aleena ponders a meditation of her own, but it would be on a far far less important topic.
[marioroy]: I'm hoping to have a release in about a week's time.

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2017-05-26 08:54 GMT
Find Nodes?
    Voting Booth?