From: Bill Kelly Date: 2004-09-16T04:09:28+09:00 Subject: Re: Ex-Perl coders: Howz it feel to convert to Ruby? Hi, From: "Chris" > > As already stated, I can usually whack out a concise, tight solution in > Perl in just a little bit of time. I'm anxious to see if I can get to > that place in Ruby and what that would look like. This sounds like Ruby > might be more suited to "bigger" tasks and Perl to the small ones. I'm > sure others will jump in here momentarily and dispute this... One of the things that thrilled me with ruby was that it didn't force me to give up quick one-off hack style scripting, in order to have a cleaner language for bigger tasks.... I invoke ruby from the command line fairly frequently, for random things like: ruby -i -pe 'gsub(/\015/,"")' *.cpp *.h If I recall my perl correctly (been about three years now) the perl is slightly shorter: perl -i -pe 's/\015//g' *.cpp *.h But ruby has proved sufficiently concise for my needs in this regard. Actually, sometimes the ruby comes out shorter than what I think the equivalent perl would be. Couple days ago a friend who has been learning ruby asked me about making a program to gather and print a sorted list of all unique IP addresses in a logfile he had. (He said a simple string-based sort was OK, and the logfile structure was simple enough that a very basic regexp would identify IP addrs without false positives.) I first approached the problem with a hash, as I would have in Perl... and then I remembered ruby has Array#uniq.... So the solution ended up being: puts ARGF.read.scan(/\d+\.\d+\.\d+\.\d+/).uniq.sort =D Not effing bad, we both thought. :) Regards, Bill