From: "Mark J. Reed" Date: 2003-08-19T14:23:03+09:00 Subject: Re: Question: immutable strings as design goal? On Tue, Aug 19, 2003 at 09:14:16AM +0900, Mark Wilson wrote: > for line in open(filename): > ...process line... Wow! What an amazing feature! How could Guido have come up with such a unique and novel idea, never seen before nor since? :) I am a big fan of File.foreach - but then I'm a big fan of the blocks and iterators in general. Actually, far from being impressed by the inclusion of this feature in Python, I'm more surprised that Perl doesn't have it. To open a file and iterate through its lines, I don't know of any Perl idiom that's much simpler than the low-levelish open/read-loop/close sequence. I think the closest you can get is something like this: { local @ARGV = ($filename); while (<>) { ...process $_... } } .. . . which saves the explicit close() line at the expense of legibility. You could also save the close line by using an IO::File instance instead of a normal filehandle: { my $fh = IO::File::->new("<$filename"); while (<$fh>) { ...process $_... } } But last I checked using IO::File really slowed things down. Anyway. Back to Ruby. :)