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

I created some perl files that I have been running and testing on an NT box, but now I need to strip out the carriage returns for the scripts to run on Unix. Is there some simple command in Unix that will do this for me?

if ($answer eq "no") {
print "What should I do?"
}

Replies are listed 'Best First'.
Re: Converting DOS perl to Unix
by KM (Priest) on May 24, 2000 at 21:37 UTC
    perl -pi~ -e 's!\r!!g' file

    Cheers,
    KM

      You are a Perl God KM!

      thnx,
      Pmint

        No, not a Perl God, simply a Perl hacker.

        Cheers,
        KM

RE: Converting DOS perl to Unix
by neshura (Chaplain) on May 24, 2000 at 21:42 UTC
    In the spirit of tmtowtdi (including using other tools besides perl), here's yet another way. i use an emacs macro -- if you use emacs, you can add this to your emacs profile:
    (defun dos-unix () (interactive) (goto-char (point-min)) (while (search-forward "\r" nil t) (replace-match ""))) (defun unix-dos () (interactive) (goto-char (point-min)) (while (search-forward "\n" nil t) (replace-match "\r\n")))
    Since I have to work with a lot of code coming in from and going back out to Windows machines, I find this easier than a one-liner. To use it is a trivial matter of calling M-x dos-unix or M-x unix-dos.

    e-mail neshura

Re: Converting DOS perl to Unix
by mdillon (Priest) on May 24, 2000 at 21:37 UTC
    #!/usr/bin/perl -w # this code acts as a simple DOS -> UNIX newline filter # set input line separator to CRLF $/ = "\r\n"; # set output line separator to LF (so we can just say 'print' # to do 'print "$_\n"') $\ = "\n"; # do it! print while (<>);
Re: Converting DOS perl to Unix
by mdillon (Priest) on May 24, 2000 at 21:46 UTC
    in VI, you can :set textmode, :e filename, :set ff=dos, and :wq
Re: Converting DOS perl to Unix
by lhoward (Vicar) on May 24, 2000 at 22:04 UTC
    Just to provide another option....

    In many cases FTPing the file in ASCII mode will handle the CR/LF conversion for you.

RE: Converting DOS perl to Unix
by Anonymous Monk on May 25, 2000 at 15:13 UTC
    Most UNIX machines have a nice little prog called dos2unix, which does exactly "what it says on the tin". See the man page for the exact syntax, I can't quite remember.
RE: Converting DOS perl to Unix
by ZZamboni (Curate) on May 24, 2000 at 23:33 UTC
RE: Converting DOS perl to Unix
by Vetere (Novice) on May 25, 2000 at 08:05 UTC
    First, try piping the files through more or less; these strip our Mac CRLFs for me just fine. If that fails, bust open vi, isolate the offending character, and :%s/character//g;
RE: Converting DOS perl to Unix
by t0mas (Priest) on May 25, 2000 at 10:32 UTC
    Why don't you just FTP it to the Unix server using ASCII mode? /t0mas