Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Modify values of tied, split lines in a file

by Crackers2 (Parson)
on Oct 22, 2012 at 19:11 UTC ( #1000405=note: print w/replies, xml ) Need Help??

in reply to Modify values of tied, split lines in a file

It seems silly to create an entire new file when I could just be editing the $c variable in the input file... am I right?

IMO, probably not, for two reasons:

  1. Speed. Say your file is 100MB in size, your first line is "a,b,c" and you want it to be "a,b,doublec" instead. If you edit in-place, that means that everything in the file after "c" will now have to be moved 6 bytes to accomodate the extra characters, so in effect you'll be doing a 100MB write just to fix the first line. Then on the second line you'll have to move everything except the first two lines again, etc. Caching probably makes it not quite as bad as it can be, but it'll likely still be much slower than just writing a new file.
  2. Error recovery; if something happens while you're in the middle of processing the file, you'll end up with half a file in the new format and half in the old format. (You could of course keep track of how many lines you've converted, but you'd have to make sure to persist that value and sync the file at the same time)
So my suggestion would be to just write the new file.

  • Comment on Re: Modify values of tied, split lines in a file

Log In?

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

How do I use this? | Other CB clients
Other Users?
Others rifling through the Monastery: (1)
As of 2022-08-08 03:31 GMT
Find Nodes?
    Voting Booth?

    No recent polls found