From: Konrad Meyer Date: 2007-10-28T08:48:04+09:00 Subject: Re: NOT reading an entire file into memory --nextPart2994194.aspd7W03tV Content-Type: text/plain; charset="utf-8" Content-Transfer-Encoding: quoted-printable Content-Disposition: inline Quoth Devi Web Development: > I am trying to write a parser for a text-based file format. Files in > this format frequently become very large. While the specification > specifically allows applications to crash on large files, I know > several people who have taken to editing these files by hand in > Notepad or other basic text editors. This format is not at all > friendly for this type of editing, and it is extremely tedious work, > but their programs all crash due to the size of these files. > What I really want to know is: > I had been using File.readline and saving a lot of temporary files via > tempfile.rb=20 (http://www.ruby-doc.org/stdlib/libdoc/tempfile/rdoc/index.html). > However, I have heard that File.readline is in fact equivalent to > File.read.split('\n').each, which would really ruin my purpose of not > loading the whole file. I'd really like to keep this in ruby, as I > want to package the whole thing via the wonderful rubyscipt2exe, as > well as, of course, a standard rubygem. > What I would actually really love is if there was a way to read lines > 4 through 7 without reading the whole file. > My current method has made the program not nearly as beautiful as ruby > ought to be. >=20 > ------------------------------------------- > Daniel Brumbaugh Keeney > Devi Web Development > Devi.WebMaster@gMail.com > ------------------------------------------- f =3D File.open("myfile") # skip through 3rd line 3.times do f.readline end Array.new(4).map do f.readline end =2D-=20 Konrad Meyer http://konrad.sobertillnoon.com/ --nextPart2994194.aspd7W03tV Content-Type: application/pgp-signature; name=signature.asc Content-Description: This is a digitally signed message part. -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.4.7 (GNU/Linux) iD8DBQBHI84xCHB0oCiR2cwRAsesAJ48vE8IHThnCWc8AX4jdarwfh0ULACeLNYr sRIpXyuajRaW0s1FKCJ51Ao= =nGo1 -----END PGP SIGNATURE----- --nextPart2994194.aspd7W03tV--