in reply to how to convert new line to ","

In principle your regex works, but probably your string on which you want to substitute doesn't contain what you think it does.

Here's an example of reading the data in paragraph mode (see $/ for an explanation) and then applying your regex:

use strict; use warnings; local $/ = ""; while (<DATA>){ chomp; s/\n/,/g; print "$_\n"; } __DATA__ 1111 2222 3333 4444 5555 6666

Replies are listed 'Best First'.
Re^2: how to convert new line to ","
by repellent (Priest) on Jul 25, 2008 at 08:07 UTC
    The shell command-line equivalent:
    cat data.txt | perl -00pe 's/\\n/,/g'
    Update: Oops! My mistake. I needed to add "-l" argument and also be careful of how the shell interprets '\n':
    cat data.txt | perl -l -00pe 's/\n/,/g'
      Did you actually test that?

      When I tried it did replace newlines with commas, but also the double newlines that bh_perl doesn't want to have replaced.

        The working line would be
        perl -00pe 'chomp; s/\n/,/g; s/$/\n/' data.txt
        and, yes, I tested it :-) the chomp yanks the last \n\n, so you must put one again at the end b4 printing.
        []s, HTH, Massa (κς,πμ,πλ)