On Tue, 16 May 2006 09:18:14 -0700, Bryan Harris wrote: > If I'm reading in many-megabyte files, is it considered to be more efficient > to read it into an array, then loop over the array? Or is reading a line at > a time okay?
Focus on *your* efficiency first, not the computer's. If you're doing line-oriented processing, read it a line at a time. If you're doing pattern matching that spans line boundaries, you'll probably want to read the whole thing in. > I realize the second will use more memory, but what's a few megabytes in > today's computers? I'm more worried about the OS having to go back to the > disk a couple hundred-thousand times -- seems like it'd be hard on the disk. Don't worry about the implementation - smart people have done that for you in optimizing the underlying code already. If you don't benchmark different ways of doing something then your guesses as to which is more efficient than another are unreliable. And don't bother benchmarking until you find out that performance improvement is necessary. -- Peter Scott http://www.perlmedic.com/ http://www.perldebugged.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] <http://learn.perl.org/> <http://learn.perl.org/first-response>