in reply to Yet another one-liner

TMTOWTDI:
perl -pi.bak -e 'BEGIN{undef $/} print "\n"' foo*
UPDATE
I am a little confused at what one-line solution I gave you. :-)

Replies are listed 'Best First'.
Re (tilly) 2: Yet another one-liner
by tilly (Archbishop) on Jan 12, 2001 at 01:57 UTC
    Fore!
    perl -pi.bak -e 'BEGIN{$/=$u}s//\n/' foo*
    PS Clarification on my update above. I don't remember giving any hints on how to do this as a one-liner.

    UPDATE
    Obvious improvement. Dropped the $ off of the u.

    UPDATE 2
    Um, without it you can add a return to the end of the file as well. The $ is back.

      Learn to love all of Perl's command line options! perl -pi.bak -0es//\\n/ foo* :)

      (Update: If your files may contain null characters, make that perl -pi.bak -0777es//\\n/ foo* instead.)

      tilly, your version:

      perl -pi.bak -e 'BEGIN{$/=$u}s//\n/' foo*

      Works fine with 5.00503, but with 5.6.0 it appends an extra newline to the file:

      $ cat > XXX 1 2 3 $ cp XXX fxx $ perl5.00503 -pi.bak -e 'BEGIN{$/=$u}s/^/\n/' fxx* $ cat fxx 1 2 3 $ cp XXX fxx $ perl5.6.0 -pi.bak -e 'BEGIN{$/=$u}s/^/\n/' fxx* $ cat fxx 1 2 3 $

      Curious.

        This is clearly a bug. According to perlrun it is supposed to be equivalent to the following loop:
        perl -i.bak -e 'BEGIN{undef $/;} while (<>) { s//\n/; print }' foo*
        but the latter is working for me on 5.6.0 and in a recent snapshot, while the former fails for me as well.

        I believe that this is a real bug.

        UPDATE
        The plot thickens. I saw your bug in both 5.6.0 and in a recent development snapshot. Turns out I had only tested the fixed version in a recent snapshot and in the original Perl. It is broken in 5.6.0 for me as well.

        However none were broken for Lexicon on NT running binary build 618 from ActiveState. It probably doesn't matter that he was running on a Japanese version of NT.