Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery

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
Node Status?
node history
Node Type: note [id://1000405]
[LanX]: Not Quite Canada
[Discipulus]: have you been fired?!?
[LanX]: remote rules, I've been offered jobs in the US with the promise to stay outside
[MidLifeXis]: Nope. Just looking around, as there are multiple culture and business changes in the area I am in.
[MidLifeXis]: not yet, anyway. Who knows. Just do my best and whatever happens happens.
[LanX]: should be even easier for you
[Discipulus]: oh well we cant afford two monks fired in a day!
[LanX]: any news from tye ' s search?
[MidLifeXis]: Ugh - who else?
[Discipulus]: so the right term is 'gired'

How do I use this? | Other CB clients
Other Users?
Others avoiding work at the Monastery: (16)
As of 2017-03-23 12:43 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (286 votes). Check out past polls.