in reply to Reading two lines per loop iteration

Good solutions above, this is how you could do it in Perl 6:

my $fh = open("file"); for =$fh->$line1,$line2 { # do whatever with the two lines }

All dogma is stupid.

Replies are listed 'Best First'.
Re^2: Reading two lines per loop iteration
by RichardJActon (Novice) on Feb 07, 2018 at 12:22 UTC

    I've been trying to do this in perl6, I can get your solution to work - perl6 may well have changed in the meantime.

    In fact I get an error message about the =$
    ... Preceding context expects a term, but found infix = instead. Did you make a mistake in Pod syntax? ... ------> for =^$fh -> $line1, $line2 {
    I had thought that something like this might work:
    my $fh = open("file"); for $fh.lines,$fh.lines -> $line1,$line2 { say $line1; say $line2; }
    but this seems to produce a rather confusing result with all the lines stuck together is a Seq, and has some EOF related error, the 'singluar form':
    for $fh.lines -> $line { say $line; }

    works fine.

    What is true is already so. Owning up to it doesn't make it worse. - Eugene Gendlin