On Thu, Nov 29, 2001 at 03:40:40PM -0600, Greg Bacon wrote:
> Sorry, I wasn't clear on an important point.  You only get one pass
> through the file.

Does the "read from the front and back" trick qualify as one or two
passes?

If not, one can do this:

    use Fcntl qw(:seek);
    open F, $ARGV[0] or die $!;

    while(<F>) {
        push @pos, tell F;
    }

    seek F, $pos[$#pos/2], SEEK_SET;
    print scalar <F>;

but I guess that qualifies as using an array.  And it's not O(1) memory.


-- 

Michael G. Schwern   <[EMAIL PROTECTED]>    http://www.pobox.com/~schwern/
Perl Quality Assurance      <[EMAIL PROTECTED]>         Kwalitee Is Job One
GOD made us funky!
      • ... Uri Guttman
        • ... Michael G Schwern
          • ... Uri Guttman
      • ... Ariel Scolnicov
      • ... abigail
  • ... Ian Phillipps
  • ... Yanick
  • ... Greg Bacon
    • ... Michael G Schwern
      • ... Dmitry Kohmanyuk Дмитрий Кохманюк
        • ... Greg Bacon
          • ... ianb
          • ... Ian Phillipps
            • ... Jonathan E. Paton
              • ... Greg Bacon
              • ... Jonathan E. Paton
              • ... Jonathan E. Paton
              • ... Ian Phillipps
          • ... Keith C. Ivey

Reply via email to