in reply to How to restart a while loop that is iterating through each line of a file?
# untested open my $read_fh, '<', 'source.txt' or die "$!"; my @lines; while (push @lines,<$read_fh>){ last if $. == 16; } foreach my $count (0..33){ open my $out, '>', 'afilename'.$count,'.log' or die "$! writing"; print $out $_ for @lines; close $out; }
But in the case you really need to restart a loop over a file read you can use seek against the filehandle.
L*
|
|---|