[Pdx-pm] read and concatenate two lines at a time
Ken Brush
ken at cgi101.com
Sun Dec 5 18:34:22 CST 2004
On Friday 03 December 2004 22:22, Michael G Schwern wrote:
> On Fri, Dec 03, 2004 at 04:05:15PM -0800, Thomas J Keller wrote:
> > Greetings,
> > I need to concatenate every two consecutive lines from a large data
> > file. Is there an easy way to do this?
>
> You're going to feel silly.
>
> while(my $entry = <>) {
> $entry .= <>;
> $entry =~ s/\n//g;
>
> ...do something with $entry...
> }
>
FYI, You can even reduce it by one more operation by doing:
while( my $entry = <> . <>) {
$entry =~ s/\n//g;
...
-Ken
More information about the Pdx-pm-list
mailing list