in reply to Re: perl 1-liner to join a list?
in thread perl 1-liner to join a list?

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.";

Replies are listed 'Best First'.
Re: * Re: perl 1-liner to join a list?
by Roy Johnson (Monsignor) on Nov 12, 2003 at 15:23 UTC
    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/,/'
Re: Re: Re: perl 1-liner to join a list?
by thelenm (Vicar) on Nov 11, 2003 at 22:53 UTC

    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