Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re: Reading two lines per loop iteration

by tirwhan (Abbot)
on Jun 09, 2007 at 13:47 UTC ( [id://620184]=note: print w/replies, xml ) Need Help??


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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://620184]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (5)
As of 2024-04-26 08:37 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found