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'.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.