in reply to Seek, whence 0 or 1

Speed in this case is a complete non-issue. Any trivial difference there may be in calculating the file position will be completely swamped by the file systems' machinations in repositioning the file I/O pointer. Use whatever is clearest in intent and easiest to maintain. You will save orders of magnitude more time that way than any execution time that may be saved, or even the time spent pondering the question.


DWIM is Perl's answer to Gödel

Replies are listed 'Best First'.
Re^2: Seek, whence 0 or 1
by Hena (Friar) on Jun 28, 2006 at 08:14 UTC
    I can quess that it doesn't help much. Mainly I'm interested on what are others opinions on which of the two seek lines is better (and tell also why and on what better) in the example above.

      Applying the test "which is easier to read and maintain" compare:

      seek (INPUT, $last, 0)

      and:

      seek (INPUT, tell (INPUT) - $last, 1);

      then tell me which is easier to read and which is easier to maintain (is less complex)? For me the absolute seek is the winner by far.

      Drawing an analogy with the way people seek in a book is not particuarly helpful as a model for analysing the pros and cons of the two seek methods by the way. Personally I tend to flip through a book from the back (seek (fh, pos, 2)) then perform a binaryish search from approximately the right place. :)


      DWIM is Perl's answer to Gödel