<?xml version="1.0" encoding="windows-1252"?>
<node id="1007569" title="Re: Reading files n lines a time" created="2012-12-06 08:40:24" updated="2012-12-06 08:40:24">
<type id="11">
note</type>
<author id="272364">
MidLifeXis</author>
<data>
<field name="doctext">
&lt;code&gt;
sub readNLines {
    my $lines_to_read = shift or die '....';
    my @lines_read;
    while(&lt;&gt;) {
        push( @lines_read, $_ );
        last if @lines_read == $lines_to_read;
    }
    if ( @lines_read != $lines_to_read ) {
        # error condition
    }
    return @lines_read;
}

while (@lines = readNLines(4)) { do_stuff() }
&lt;/code&gt;
&lt;p&gt;I might even consider the question "What am I reading from the file?" - if it is a record, then I might instead change &lt;c&gt;readNLines&lt;/c&gt; to &lt;c&gt;readRecord&lt;/c&gt; (as well as the surrounding usage of the data).  Then the concept is abstract, and if the format of a record changes, you modify the reading piece.  In my opinion, 
&lt;code&gt;
    while ( my $record = readRecord( ... ) ) { ... }
&lt;/code&gt;
tells me much more in the context that I am concerned with than
&lt;code&gt;
    while ( $line1=&lt;&gt; &amp;&amp; $line2=&lt;&gt; &amp;&amp; $line3=&lt;&gt;... ) { ... }
&lt;/code&gt;
&lt;/p&gt;
&lt;p&gt;Just my $0.02.&lt;/p&gt;
&lt;div class="pmsig"&gt;&lt;div class="pmsig-272364"&gt;
&lt;p&gt;--MidLifeXis&lt;/p&gt;

&lt;/div&gt;&lt;/div&gt;</field>
<field name="root_node">
1007560</field>
<field name="parent_node">
1007560</field>
</data>
</node>
