You could always haul the entire file in and chunk it out,
or you could just re-work how you're using Perl:
#!/usr/bin/perl -w
use strict;
use warnings;
my @three;
# Stoke it
chomp ($three[0] = <DATA>);
chomp ($three[1] = <DATA>);
while(!eof(DATA))
{
chomp ($three[2] = <DATA>);
# Do stuff to process @three
print join ("\t", @three), "\n";
# Rotate
shift(@three);
}
__DATA__
1
2
3
4
5
6
This is simply using the
shift function to rotate the
array as you insert new data. Some notes on your implementation:
- Don't put any "warm up" code inside the loop, put it before the loop. This eliminates the CALL sub-loop,
and any associated ambiguity with last.
- Don't name your loops for no reason. In this case, you are using last to escape a single loop, not several in a single call, so it is redundant.
- You're backtracking within the file using seek, which
seems a little overkill, since you already have the data in @three. Shuffle it around using array methods instead of reading it again and again needlessly.
- Your use of the ?: operator is, while valid, kind of unfortunate. It is normally used in an inline capacity, such as where there is no room for an if. While it might take more room, using if will make it a lot clearer what you're doing.
Still, points for 'use warnings' and 'use strict'.