in reply to Adding rows to column

Sounds like an identical question to Concatenate every 5 lines of input with a comma.. What follows is my earlier answer:


As a one-liner:

perl -ple'$\ = $. % 5 ? ";" : $/' infile > outfile

In-place:

perl -i.bak -ple'$\ = $. % 5 ? ";" : $/' file

If it wasn't a one-liner,

while (<$fh>) { chomp; print $_, $. % 5 ? ";" : $/; }

PerlMonks formatting tip: Use <c>...</c> around computer text (code and data), and use <p> at the start of each paragraph.

Replies are listed 'Best First'.
Re^2: Adding rows to column
by Anonymous Monk on Jul 14, 2009 at 19:12 UTC
    Thanks for the response. Any idea, why i'm getting this error : Global symbol "$fh" requires explicit package name at cgrpioneer.pl line 7. I even added the following line, but still the same. my $fh; Thanks, Pamela Honeycutt
      In the example there, $fh is the filehandle you want to read from.
      You should open my $fh, '<', "somefile.txt" or die $!; somewhere earlier in the program.

      PS: Simply saying that you added my $fh; doesn't help. You need to show the code, or the problem could be anything anywhere.
        Thanks a Lot, it's working.