From: Robert Klemme Date: 2004-09-17T01:09:47+09:00 Subject: Re: Ex-Perl coders: Howz it feel to convert to Ruby? "James F. Hranicky" schrieb im Newsbeitrag news:20040916115917.0ab545bf.jfh@cise.ufl.edu... > On Wed, 15 Sep 2004 23:54:51 +0900 > Chris wrote: > > > So I'm looking for feedback from those that have converted, esp. from a > > hardcore Perl perspective. > > Recently it dawned on me that one of the reasons I like Ruby so much is > method chaning. Why? At first, I thought it was because the program > flow went left to right, just like reading. But then it occurred to me > that being able to do something like this: > > `ypcat -k amd_cise`.map { |line| > line.match(/rhost:=([^;]+)/).captures[0] rescue next > }.compact.sort.uniq.each { |server| > ... > > is just like using Unix pipes. When I used perl, and I needed to process > the output of a command like the above, I would generally do all the > work with a regular Unix pipeline. With ruby, the processing is very > similar already. You have to do a little more work, like catching > exceptions and things like nil elements, but the program flow is so > natural there's no need to exec the extra programs. The only caveat here being to remember that typically with method chaining you build up one collection before the next step starts; in cases of mass data this can be rather impractical, whereas pipes only need limited temp storage (sort and other programs that need to see the whole input are an exception here). But otherwise: yes, well observed! > I recently tried hacking on some Perl (I've written thousands of lines > over the years), and I can barely even remember what to do, which is > fine, really :-> :-) robert