bambam has asked for the wisdom of the Perl Monks concerning the following question:

Hi, is there a way to set $/ to read in double lines at a time?

Replies are listed 'Best First'.
Re: Reading double lines at a time
by Eureka_sg (Monk) on May 07, 2001 at 11:39 UTC

    Not to my knowledge

     $/ = undef ==> Read in entire file
     $/ = '' ==> Read by paragraphs
     $/ = 'c' ==> Read until 'c' is encountered

    However, you can do something like this:

    while(<FILE>){ $_ .= defined(my $temp = <FILE>)?$temp:''; #do whatever you want with $_ }
Re: Reading double lines at a time
by cLive ;-) (Prior) on May 08, 2001 at 05:38 UTC

    No, unless your double lines have a unique delimiter. But, let's say you're reading FILEHANDLE...

    while (1) { $double_line = (<FILEHANDLE>).(<FILEHANDLE>) || last; print $double_line."\n---------\n"; }

    Is that what you're looking for?

    cLive ;-)