Beefy Boxes and Bandwidth Generously Provided by pair Networks
Your skill will accomplish
what the force of many cannot

Re: How smart is 'seek $fh, $pos, 0'?

by sundialsvc4 (Abbot)
on May 27, 2015 at 15:49 UTC ( #1128026=note: print w/replies, xml ) Need Help??

in reply to How smart is 'seek $fh, $pos, 0'?

Very interesting results, BrowserUK, and most certainly unexpected.   Every operating system, that I know of, provides an API-call that is equivalent to fseek().   I presume (but have not verified ...) that the perlguts simply uses that call.   I also have not verified that the underlying OS-implementation (in any particular OS ...) has any sort of dramatically-different execution time for any of the (usually, three) variations of that call.

Certainly, “seek from the end” would require a little bit of extra work, since one would need to be sure that the current size of the file was atomically and correctly known, even for a shared file.   But I would not expect the OS, nor Perl, to “cache the entire file” in order to determine that!

Anyhow ... “very interesting.”   I guess you learn something new every day.   Thanks for sharing.

Now, as for what the OP in this case should do, my instincts would tell me to tell him to “just be perfectly clear.”   To not be overly concerned about milliseconds unless those milliseconds actually matter.   (As I well know that, in your line of work, BrowserUK, they often do ... very much so.)   Use the system-call that most closely matches the way that you would describe your application’s intentions if you were describing it over the water-cooler, and to assume (hope?) that the call is “smart enough for peace work.”

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1128026]
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others studying the Monastery: (2)
As of 2020-10-25 20:21 GMT
Find Nodes?
    Voting Booth?
    My favourite web site is:

    Results (249 votes). Check out past polls.