in reply to Re: Having Access to a file two times
in thread Having Access to a file two times

Hi Dave,

I check the perl doc for SEEK. after the first while but before closing the file. I Added,

seek , 0, 1;

while <FH> ...

it did not work, Is this the right way of using SEEk?

  • Comment on Re^2: Having Access to a file two times

Replies are listed 'Best First'.
Re^3: Having Access to a file two times
by AnomalousMonk (Archbishop) on Sep 21, 2008 at 08:31 UTC
    No: you need to specify a filehandle.
    seek FH, 0, 1;
    Take another look at the seek docs.

    It's also nice to check the return status of the file operation for success:

    seek FH, 0, 1 or die "seek failed: $!";
      You mean ..
      seek FH, 0, 0;
      .. assuming the aim is to rewind back to the start.

        Or even better:

        use Fcntl qw/:seek/; seek FH, 0, SEEK_SET or die "Cannot seek on $filename: $!";
        Quite right!   Looks like I need to take another look at the seek docs.