in reply to perl 1-liner to join a list?


Another way:
perl -lpe '$\=(eof)?$/:","' file

Update: or this

perl -l54pe '$\=$/if+eof' file

--
John.

Replies are listed 'Best First'.
Re: Re: perl 1-liner to join a list?
by sauoq (Abbot) on Nov 11, 2003 at 22:17 UTC

    You've still got me by one character... perl -0pe 'y/\n/,/;s/,$/\n/'

    Update: But, wait!

    perl -0pe 's/\n(?!$)/,/g'
    :-)

    -sauoq
    "My two cents aren't worth a dime.";
    
      This was a gimme from my earlier post. It's also fairly readable. Compared to yours, the expression is 1 char shorter, and there's one fewer command-line option.
      perl -pe 'eof||y/\n/,/'

      So it's golf, is it? :-)

      perl -lpe '$\=!eof&&","'

      Update: Uh, hmm, just realized that doesn't quite do the same thing (gets rid of the trailing newline). Bah, details.

      -- Mike

      --
      XML::Simpler does not require XML::Parser or a SAX parser. It does require File::Slurp.
      -- grantm, perldoc XML::Simpler