in reply to Merge pairs of lines

Using next that way doesn't play with -p unfortunately. Ignoring that issue, here's a doozy to do the same:
perl -l054p012e'($\,$a)=($a||$\,$b||$/);$b=$\'

:-)

Update:

$ perl -l054p012e'($\,$a)=($a||$\,$b||$/);$b=$\' <<EOT
> a
> b
> c
> d
> e
> f
> g
> h
> EOT
a,b
c,d
e,f
g,h

Makeshifts last the longest.

Replies are listed 'Best First'.
Re: Re: Merge pairs of lines
by sauoq (Abbot) on Jan 31, 2003 at 05:48 UTC

    My attempt,

    perl -pe '$_=/\S/?do{chop;$_.",".<>}:""'
    assumes non-blank lines come in pairs.

    Yours doesn't look right to me though...

    286,0 sauoq@grover:~$ perl -l054p012e'($\,$a)=($a||$\,$b||$/);$b=$\' < + test.txt a,b ,c d,287,0 sauoq@grover:~$ cat test.txt a b c d 288,0 sauoq@grover:~$
    -sauoq
    "My two cents aren't worth a dime.";
    
      It ignores the issues of blank lines, if you mean that, but so does the OP's code because next doesn't work the way he thinks. (The print is in a continue block so it always gets executed short of dieing.) I chose to note and ignore it. What I was trying to do is achieve the described behaviour without explicitly manipulating $_ or printing anything myself.

      Makeshifts last the longest.