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

Re: (OT) Fixing Line Endings

by serf (Chaplain)
on Dec 01, 2006 at 09:40 UTC ( [id://587147]=note: print w/replies, xml ) Need Help??


in reply to (OT) Fixing Line Endings

Hi Ovid,

Good question! :o)

I agree with your response to rhesa's suggestion too - when the kind of user who is going to send a file in binary mode is in a stressed state trying to figure out why the Perl isn't where it's meant to be (because that's what they'll be thinking when they see the error) often the last thing they're going to think about is the fact that they may or may not have been told that they should transfer their files in ASCII mode - which might not have meant anything to them at the time they were told it.

You either need to stop these problems from happening, or alternatively have something there and then to tell them the cause of their problem so they can quickly fix it themselves.

Not teaching you to suck eggs, the rest of this post is for anyone else reading this looking for answers to the same kind of problem:

For generating the link, from the command line in bash the original person could have just done this:

ln -s /usr/bin/perl "/usr/bin/perl$(echo -e "\r")"

Or in 'set -o vi' mode in bash or Korn shell they could have just typed this:

ln -s /usr/bin/perl /usr/bin/perl^V^M
(For those that don't know, ^V^M is typed [Ctrl+V][Ctrl+M])

Another solution I used when I used to host shell accounts for my friends on my Internet server (to help them learn how to use Linux) and was getting fed up with having to regularly look at their scripts for them to tell them why they would not run... was to compile a little C program which just generated a warning message telling them what was wrong, and install that as /bin/bash^M on my system so that the user would understand the problem and fix it themselves.

This is on my old machine:
$ ls /bin/bash* | cat -v /bin/bash /bin/bash^M $ file /bin/bash^M : ELF 32-bit LSB executable, Intel 80386, version 1 (SYSV), for GNU/Li +nux 2.0.30, dynamically linked (uses shared libs), for GNU/Linux 2.0. +30, stripped $ /bin/bash^M Your shell script has DOS linefeeds in it!

You could do the same thing with /usr/bin/perl^M

If my users were the kind who wouldn't know what that meant I would probably add some extra hints, like:
Your Perl script has DOS linefeeds in it! If you uploaded it to the server via FTP please upload it again in ASC +II mode.
For users with shell access I would probably add a message about dos2ux or saving it after doing:
set ff=unix
in vim or doing:
:%s/^V^M//g
and saving it...

But I expect the majority of people running Perl scripts that have been sent from a CRLF machine probably have FTP/web access only.

If anybody reading this is thinking about just copying /usr/bin/perl to /usr/bin/perl^M for any reason - don't do it, use the symlink instead.

If you just copy the file, when you upgrade perl you will be left with an orphaned copy of the old version unless you (and whoever comes after you in supporting the machine) always remembers to upgrade that file too = not clever.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-23 21:27 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found