-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On Wed, 29 Aug 2001 05:42, Christophe Broult wrote: > > -----Original Message----- > > From: Ryan [mailto:ryan / ryanflynn.com] > > Sent: Tuesday, August 28, 2001 1:38 PM > > To: ruby-talk / ruby-lang.org > > Subject: [ruby-talk:20478] Re: File.readline(s) > > > > > def read_f(name) > > > n = 0 > > > line = "" > > > f = File.open(name) > > > f.each_line{|line| > > > n += 1 > > > } > > > n > > > end > > > > Instead of looping couldn't you just do: > > > > puts IO.readlines("c:/file.txt").length > > > > ? I'm a newbie, so feel free to correct me if this is not kosher. > > IO.readlines load the entire file in memory. So if the file is big > this is not what you want to do... > > Christophe Perhaps, but surely that is what the previous code is doing, simple counting all the lines in the file. - -- Signed, Holden Glova -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (GNU/Linux) Comment: For info see http://www.gnupg.org iD8DBQE7jJFX+mF116Lw2cQRAm5pAJ9DzBa/xk3145wfGY53LMRhAzdRegCeKui1 FZGeAMHh1OVmtcAZYFOPKTs= =az8K -----END PGP SIGNATURE-----