Ruby Ninjitsu

I am still working on my Perl script for my pattern recognition class. There was a time a few years ago when I swore by Perl. Since learning Ruby though, I really feel like Perl is clunky. This is what really drove it home in Ruby I can do something like,

str = “1.2 3.4 3.4 1 2 3 classx”
class = str.split(‘ ‘)[-1]

In Perl I have to do,

my $str = “1.2 3.4 3.4 1 2 3 classx”;
my @tmp = split(‘ ‘, $str);
my $class = $tmp[-1];

One extra line, big deal right? But look at how much cleaner the Ruby code looks. Now, extend that purity throughout a few hundred or thousand lines. It truly is amazing at how clean and sweet and powerful Ruby is.

Leave a Reply

%d