Joe_Cullity has asked for the wisdom of the Perl Monks concerning the following question:

I'm haveing a problem where the use of SEEK_END does not seem to work in seek(file_handel, offse, wence)" As used in my program
open ($archive_file_handel, '+<', $archive_file_spec) or die "Can't op +en $archive_file_spec: $!"; $first_line = <$archive_file_handel>; # actually only line seek($archive_file_handel, 0, 2); # works , appends to end seek($archive_file_handel, 0, SEEK_END); # fails, writes to begining print { $archive_file_handel } "another piece of data to go after head +er\n"; # Write out junk for now
I'm just using the seek(handel, 0, 2) for now, but would like comments if anyone has any ideas. Joe_Cullity

Replies are listed 'Best First'.
Re: Question on seek()
by borisz (Canon) on Aug 04, 2005 at 19:18 UTC
    Perhaps you did not import SEEK_END and you did not use warnings?
    use Fcntl ':seek'; ... # your code here
    Boris
      Thanks Boris that worked fine. One of the things that throws me using Perl vs C/C++ is that C/C++ always mentions what includes you need, but I don't see any equivelent in perl to let you know what "use" moduals one needs to request.
        but I don't see any equivelent in perl to let you know what "use" moduals one needs to request.
        From the perl documentation for seek:
        For WHENCE you may use the constants "SEEK_SET", "SEEK_CUR", and "SEEK_END" (start of the file, current position, end of the file) from the Fcntl module.

        Dave.

        Hmm my C does not. It just tells that something is missing. perl does this also with warnings enabled. Start any of you scripts with:
        use strict; use warnings;
        I learned about the constants for seek from the docs of seek.
        Boris