Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!news.musoftware.de!wum.musoftware.de!de-l.enfer-du-nord.net!feeder2.enfer-du-nord.net!talisker.lacave.net!lacave.net!not-for-mail From: jake kaiden Newsgroups: comp.lang.ruby Subject: Re: File position and buffers Date: Thu, 28 Apr 2011 22:36:38 -0500 Organization: Service de news de lacave.net Lines: 44 Message-ID: <79209ef84d9aba12fbb512ee6f18e427@ruby-forum.com> References: <10d8ae57765e21626a7c64873dcba807@ruby-forum.com> NNTP-Posting-Host: bristol.highgroove.com Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 7bit X-Trace: talisker.lacave.net 1304048420 18828 65.111.164.187 (29 Apr 2011 03:40:20 GMT) X-Complaints-To: abuse@lacave.net NNTP-Posting-Date: Fri, 29 Apr 2011 03:40:20 +0000 (UTC) In-Reply-To: <10d8ae57765e21626a7c64873dcba807@ruby-forum.com> X-Received-From: This message has been automatically forwarded from the ruby-talk mailing list by a gateway at comp.lang.ruby. If it is SPAM, it did not originate at comp.lang.ruby. Please report the original sender, and not us. Thanks! For more details about this gateway, please visit: http://blog.grayproductions.net/categories/the_gateway X-Mail-Count: 382355 X-Ml-Name: ruby-talk X-Rubymirror: Yes X-Ruby-Talk: <79209ef84d9aba12fbb512ee6f18e427@ruby-forum.com> Xref: x330-a1.tempe.blueboxinc.net comp.lang.ruby:3674 hi Cee - copying the text you posted above into the file "0text.txt" and running this: f = "0text.txt" file = File.open(f) buffer = [] bufferindex = 0 file.each_line(sep=">"){|line| buffer[bufferindex] = line.chomp bufferkey+=1 } p buffer[0] p buffer[1] p buffer[2] p buffer[3] i get this as output: #=> ">" #=> "gi|329295464|ref|NM_2005745.3Acc1| Def1 zgc:65895 (zgc:65895), mRNA\\n\nAGCTCGGGGGCTCTAGCGATTTAAGGAGCGATGCGATCGAGCTGACCGTCGCG\\n\n\\n\n>" #=> "gi|456299107|ref|NM_2342343.3Acc2| Def2 zgc:65895 (zgc:65895), mRNA\\n\nGTCGCTGGGTCGAAAAGTGGTGCTATATCGCGGCTCGCGTCGATGTCGCGATG\\n\nCGTGCGCGCGAGAGCGCGCTATGATGAAAGGATGAGAGAG\\n\n\\n\n>" #=> "gi|3542945647|ref|NM_7453343.5Acc3| Def3 zgc:65895 (zgc:65895), mRNA\\n\nCGTGCGGGGABCCGTACGTGCCGTGGGGGTTTAATAGCGCGCCATCTGAGCAG\\n\nTTAGTCGCTGACGCATGCACG\\n\n\\n" does this work for you? you could easily write ways to deal with, dump, and reset the buffers when they fill up. you can of course also clean up all the "\n"'s... i agree with 7stud that using #.pos and #.gets seems like a long walk off a short pier. i'm pretty green myself, and there are probably better ways to iterate through the file, but #.each_line(sep=">") works just fine, and doesn't eat up memory. - j -- Posted via http://www.ruby-forum.com/.