From: John Carter Date: 2007-03-05T09:25:09+09:00 Subject: Re: Altering 1 line in an existing file On Mon, 5 Mar 2007, Jason wrote: > I'm in the process of creating an application launcher in ruby. I've hit > one little hang up though. I want to have the launcher access a file > containing a log of how many times each application has been run, for > ranking purposes. Don't forget the Atomic unit of writing for disk files is a cluster. A cluster is 4096 bytes on an ext3 fs (I believe) ie. Even if you just wish to change 1 byte on the disk, the disk is going to be doing (at least) a 4096 byte write. > What I want to do is take "newRanking" and overwrite the old ranking > (existingRanking) in the file. I've seen some people recommend writing a > whole new file and destroying the old one. It seems like there should be > a more elegant way of doing this though. Any ideas? If the file is significantly bigger than 4096 bytes, you can divide it up into fix length records and to seeks and syswrites. Although by the time you get into that sort of thing using a standard ISAM library like libgdbm is often best. Ruby has bindings for it. John Carter Phone : (64)(3) 358 6639 Tait Electronics Fax : (64)(3) 359 4632 PO Box 1645 Christchurch Email : john.carter@tait.co.nz New Zealand