From: Chad Perrin Date: 2008-11-16T09:32:23+09:00 Subject: Re: IO#lineno= doesn't work the way I expected --qMm9M+Fa2AknHoGS Content-Type: text/plain; charset=us-ascii Content-Disposition: inline Content-Transfer-Encoding: quoted-printable On Sun, Nov 16, 2008 at 05:42:18AM +0900, Tim Hunter wrote: > Chad Perrin wrote: > > 2. Is there a way to do what I actually need -- specifically, to > > iterate over an entire file *except* the first line, only reading one > > line at a time into RAM -- without writing a C extension for Ruby? >=20 > Why not iterate over the entire file and just ignore the first line?=20 > IO#readline or IO#gets will get you a line at a time. How do you propose I "ignore" the first line? That's what I was trying to do -- by starting the iteration over lines in the file with the second line. Are you saying I should just have an orphan gets line in the code, then have a block in which I use gets each line until I run out of file? I guess that would probably work, but seems kinda . . . ugly. I just need to figure out an efficient way to calculate the number of lines in the file (minus one) now so I can use that number to control the number of iterations. I really hope you aren't suggesting I have a conditional in every single iteration, going through all the lines in the file, to test whether it's the first line so the first line can be ignored. =2E . . and why is there a lineno and a lineno=3D if lineno=3D doesn't actu= ally do anything other than prompt you for a useless number? I still don't understand that. --=20 Chad Perrin [ content licensed PDL: http://pdl.apotheon.org ] Baltasar Gracian: "A wise man gets more from his enemies than a fool from his friends." --qMm9M+Fa2AknHoGS Content-Type: application/pgp-signature Content-Disposition: inline -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.9 (FreeBSD) iEYEARECAAYFAkkfauIACgkQ9mn/Pj01uKUeQgCg0R79YN2hR/TvrTAYuP068bk/ VPAAn303fzFGS3BSWoRhqmNINekyg5eA =/cO+ -----END PGP SIGNATURE----- --qMm9M+Fa2AknHoGS--