Giuseppe Bilotta wrote:

>Is there some (semi)automatic way to attempt such a thing? Or does it 
>have sense at all?
>
I converted some of my Perl scripts to Ruby and a first attempt which 
was more of a transliteration (?) ended up looked like very bad Perl and 
even worse Ruby.

Rewriting produced a much better Ruby program. Perl, as she is commonly 
written, seperates the data from the logic whereas Ruby merges to two.

This in Perl

for(my $x = 0; $x < scalar(@accounts}; $x++) {
    $accounts[$x]->interest = ($accounts[$x]->holding * $interestrate);
}

becomes

accounts.each {| account | account.interest(interestrate)}

Ok there are other ways of writting that loop in Perl but they all 
introduce an unnecessary variable such as $x even if it is the implicit $_.

Perl tells you 'what to do' whereas Ruby tells you 'what it is doing'.

A lot of the data that Perl holds externally or at least needs to access 
externally (such as $accounts[$x]->holding) is made internal in Ruby and 
stays there. Indeed interestrate could be a class variable but that 
probably wouldn't be how I'd do it.

When a program can convert the above Perl into the Ruby then we are all 
out of a job.

Even good OO Perl tends to contain much 'paperwork' that Ruby handles 
for you. You will never have to bless something again.

Besides code invariably gets better the more you rewrite it.