in reply to Merge pairs of lines

Now that I've actually tested the code, I have a bugfix for it:
perl -pe 'goto LINE unless /\S/; s/\n/,/ if ($a = 1 - $a)'
This fix keeps the structure of the original code, only changing the next to a goto.

--
integral, resident of freenode's #perl

Replies are listed 'Best First'.
Re: Re: Merge pairs of lines
by sauoq (Abbot) on Jan 31, 2003 at 21:35 UTC
    Now that I've actually tested the code, I have a bugfix for it:

    You should test before submitting a snippet.

    Even this version has a quirk you should be aware of. It will substitute a comma for a newline on the last line of the file if the input has an odd number of non-blank lines.

    You can use $a ^= 1 as a sufficiently clear alternative to $a = 1 - $a.

    Golfed: perl -pe 'goto LINE if!/\S/;--$|&&s/\n/,/'

    Update: Another several strokes shaved:

    perl -pe '/\S/?--$|&&s/\n/,/:($_="")'

    -sauoq
    "My two cents aren't worth a dime.";