From: Daniel Bush Date: 2008-08-24T08:23:39+09:00 Subject: Re: Open file, get first line, delete first line close file Richard Schneeman wrote: > Hey, i'm trying to open a file, get the first line of the file, delete > that line from the file, and then close the file. Using ruby 1.8.6. > > I've tried using > > The_File = IO.readlines("public/languages/chinese/practice.txt") > > & > > The_File = open('public/languages/chinese/practice.txt','r+') > > but i can't figure out the correct syntax for how to delete a line in a > file, and then save that file. Simplest thing is to get it into memory like you did with readlines above and write out the altered contents to a new file and then move it. (I prefer File.readlines - although this is the same method either way). Large files might require different treatment rather than slurping into memory like that. That being said, I'd be curious to hear how people use r+ mode. Daniel -- Posted via http://www.ruby-forum.com/.