Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^4: advancing in file read

by ikegami (Patriarch)
on May 16, 2010 at 21:26 UTC ( [id://840263]=note: print w/replies, xml ) Need Help??


in reply to Re^3: advancing in file read
in thread advancing in file read

So
my @array = <$fh>; for (my $i=0; $i<@array; ++$i) { my $line = $array[$i]; ... if (...) { defined( my $next_line = $array[++$i] ) or die; ... } ... }

It's simpler just doing

while (my $line = <$fh>) { ... if (...) { defined( my $next_line = <$fh> ) or die; ... } ... }

Replies are listed 'Best First'.
Re^5: advancing in file read
by apl (Monsignor) on May 17, 2010 at 10:34 UTC
    It is if the same processing must be applied to every line in the file, even if said line was the second line of an earlier piece of processing.

    Requiring the file be read at the top of the loop denies you the ability to reprocess the second line. The OP had said

    And is there a way to advance the file handle so it doesn't re-read the next line in the foreach loop?

      It's my understanding that the OP doesn't want to re-read the line because he doesn't want to reprocess it, not for efficiency purposes.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others chanting in the Monastery: (6)
As of 2024-03-28 20:06 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found