in reply to Grabbing lines three-by-three from a file

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: Still, points for 'use warnings' and 'use strict'.

Replies are listed 'Best First'.
Re: Re: Grabbing lines three-by-three from a file
by runrig (Abbot) on Dec 11, 2001 at 00:59 UTC
    Don't name your loops for no reason.

    IMHO, there's nothing wrong with naming your loops, especially (but not only) when there are multiple or nested loops in the general vicinity. It just makes things more clear, and more self-documenting.

      The last function, by definition, bails out of the loop that it is currently inside. If there was any confusion as to where the last call would be tossing program flow to, a comment might help. The loop label indicates the start of the loop, not the finish, so you have to read backwards to find the label, then scan fowards to find the loop finish point.

      Why not this?
      while (something()) { # Lots of stuff, nested functions, etc. last if ($condition); # Move to Post-Processing # Lots more stuff } # Post-Processing more_stuff();
      Instead of:
      PROCESS: while (something()) { # Lots of stuff, nested functions, etc. last PROCESS if ($condition); # Lots more stuff } more_stuff();
      If the while() structure was very long, it might be easier to scan for a carefully worded comment.

      If you have a reason for putting loop labels in, by all means put them in. All I'm advocating is that there shouldn't be things in a program that are there for no reason.

      Or maybe I just don't like Perl programs which feel like:
      _10: print "Hello"; _20: goto _10;