in reply to Using in multiple passes

merlyn's answer is only good for small file (i.e. ones that fit in the memory you have available for this proccess).

If the file can be big, then you should favor multiple passes as you requested originally. To do this, use:

seek(FILEHANDLE, SEEK_SET, 0)
between the passes to go back to the beginning.

Replies are listed 'Best First'.
RE: Re: Using in multiple passes
by merlyn (Sage) on Oct 25, 2000 at 18:06 UTC
      Yes, of course.

      Just for curiousity, i tried the following:

      #!/usr/bin/perl -w while(<>) { print }; seek(STDIN, 0, 0) or die; print "-----PASS 2-----\n"; while(<>) {print}
      and ran it with:     > ./t.pl < t.pl and it did read the file twice! How come?
      (I was expecting an error like 'non-seekable file' or so.)

      When doing

      >cat t.pl | perl t.pl
      it died where it should have (i.e. in the seek()).