From: Chad Perrin Date: 2005-12-13T05:56:41+09:00 Subject: Re: new to Ruby - pls help in translating this On Tue, Dec 13, 2005 at 03:46:09AM +0900, James Edward Gray II wrote: > On Dec 12, 2005, at 12:32 PM, William James wrote: > > >Also, as in Awk, "print" with no argument prints the line just read. > >Very simple. If one needs to explicitly refer to the line just read, > >one uses "$_". > > > >And "while gets" is simpler and clearer than "ARGF.each do |elem|". > > You would get a lot of support in Perland, but this kind of code is > very out of fashion in the Ruby community. I can see, for readability's sake, wanting to avoid non-explicit data handling like using "print" with no argument. Yes, that's the sort of thing that allows three lines of Perl to do the same work at a dozen or more of many other languages, but it's not very clear and is easy to break later when maintaining the script. I don't see any particular reason to regard "ARGF.each do |elem|" as better than "while gets", though. The latter of the two is more like natural language, reads clearly, and is pretty much intuitively understandable even to people who have never touched the language before. As I understand it, the "Ruby way" tends toward simplicity, elegance, and ease of reading, writing, and maintaining. From what I can see, "while gets" satisfies those preferences better than "ARGF.each do |elem|". In fact, I'd say that regardless of whether "ARGF.each do |elem|" is what "everyone uses", it is "while gets" that seems to best suit the spirit of the "Ruby way". . . . and even if I'm missing some esoteric point regarding how the language works, and the way "while gets" operates does NOT suit as well as I think at first glance, perhaps it SHOULD. Please let me know if I'm missing something. I've got a head full of snot today, and the sinus pressure might just be making me stupid. -- Chad Perrin [ CCD CopyWrite | http://ccd.apotheon.org ] unix virus: If you're using a unixlike OS, please forward this to 20 others and erase your system partition.