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

How do people chomp out a ^M symbol in *NIX?

Title edit by tye

Replies are listed 'Best First'.
Re: chomp
by Juerd (Abbot) on Jun 13, 2003 at 13:14 UTC

    How do people chomp out a ^M symbol in *NIX?

    chomp (click link; read documentation; do so now) uses $/. If you don't want to change $/, you can't use chomp to do what you want. In that case a simple regex or transliteration suffices: s/\cM//g or tr/\cM//d. The latter is faster.

    Juerd # { site => 'juerd.nl', plp_site => 'plp.juerd.nl', do_not_use => 'spamtrap' }

Re: chomp
by Skeeve (Parson) on Jun 13, 2003 at 14:04 UTC
    I prefer to do it like this:
    s/[\r\n]+$//;
    This will take care of any line-end, might it be DOS (CR LF), *NIX (LF) or Mac (CR).
Re: chomp
by benn (Vicar) on Jun 13, 2003 at 15:55 UTC
    Sorry to have to say it mate, but you're an Xperienced monk who's been here 8 months - ever noticed the search box at the top of the page? Just typing '^M' in there brings up a whole host of entries...or you could use the cho^Mper, but it would have to be searching in 1% increments :)

    Ben.

Re: chomp
by flounder99 (Friar) on Jun 13, 2003 at 14:59 UTC
    This may not be a perl soluition but check if your system has dos2unix or d2u these utilities convert CRLF to LF. Read the man dos2unix or man d2u pages to see how to use them.

    --

    flounder

Re: chomp ^M ?
by strat (Canon) on Jun 14, 2003 at 08:58 UTC
    Or with a file as a one-liner:
    perl -i.bak -pe 's/\r//g' filename

    Best regards,
    perl -e "s>>*F>e=>y)\*martinF)stronat)=>print,print v8.8.8.32.11.32"