in reply to Re (tilly) 1: Yet another one-liner
in thread Yet another one-liner

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.

Replies are listed 'Best First'.
Re: Re (tilly) 2: Yet another one-liner
by chipmunk (Parson) on Jan 12, 2001 at 02:10 UTC
    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.)

Re: Re (tilly) 2: Yet another one-liner
by danger (Priest) on Jan 12, 2001 at 02:56 UTC

    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.