[Israel.pm] Another perl vs ruby

ynon perek ynonperek at gmail.com
Wed Mar 28 01:55:44 PDT 2012

Hi All,

A student asked me for a perl solution to the problem at the bottom.

I went for both Ruby and Perl solutions, and here's some thoughts:

Perl sigils are cool and help understand the code. I really love them -
BUT, I think they actually hurt readability on some cases. For example, I
found ruby's *array.clone* far more readable than perl's [ @$array ]

Also, I found it easier to use subroutine refs in perl than in Ruby (not
sure that's a good thing - code came out less readable).

OTOH, some things that surprised me in ruby:

Ruby has too many number types (I had to use .to_f function to get floating
point division).
It's not possible in ruby to use a function before it is declared (forced
me to write code at the bottom)
Ruby has no labels (making it hard to break from the outer loop)

All code (ruby + perl) is on a public gist:

Your comments and thoughts are very welcomed,


Write a program that takes a list of numbers, a list of operators, and a
goal; and tells the user which mathematical operations must be performed to
reach the goal. For example, given the input:
numbers: 2, 4, 6, 8
operators: +, -, *, /
goal: 25

Program should produce the output:
sol = (((2 / 8) + 6) * 4)
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://mail.perl.org.il/pipermail/perl/attachments/20120328/ef6b1ead/attachment.htm 

More information about the Perl mailing list