Beefy Boxes and Bandwidth Generously Provided by pair Networks
The stupid question is the question not asked
 
PerlMonks  

Re: writing to the top of a file

by BrowserUk (Patriarch)
on May 20, 2004 at 03:36 UTC ( [id://354845]=note: print w/replies, xml ) Need Help??


in reply to writing to the top of a file

Unless reads from this file are considerably more frequent than writes, reading the whole file and then re-writing it with the new stuff at the top in order to speed up reads will have dubious benefit.

If the reads and writes are paired (equal numbers of each) then one cycle of 'Writing to the end of file + reading the whole file to get the last line' compares favourably with 'Reading the whole file, writing the new line and then re-writing the whole file + reading the first line'.

You would almost certainly be better of writing new stuff to the end, and then using File::ReadBackwards or a similar technique to retrieve it.


Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"Think for yourself!" - Abigail

Replies are listed 'Best First'.
Re: Re: writing to the top of a file
by bibo (Pilgrim) on May 20, 2004 at 13:37 UTC
    I concur. Even sucking the whole file in with @lines = <$INFILE>; and just printing the results in reverse order makes more sense than physically writing to the file in such an unnatural order. Of course, that presumes the file is not of a monstrous size, etc etc.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (9)
As of 2024-03-28 10:13 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found