From: "David A. Black" Date: 2004-09-16T04:41:32+09:00 Subject: Re: Ex-Perl coders: Howz it feel to convert to Ruby? Hi -- On Thu, 16 Sep 2004, Chris wrote: > (3) Another contrived example, this time in Ruby: > > def Contrived > 3.times { yield } > end > > [ "tic", "tac", "toe" ].each do |item| > Contrived { printf "%s ", item } > printf "\n" > end > > There is a lot about this that is different than Perl IMO. I could > create an anonymous subroutine in Perl to function something like the > yield block, and I realize the Ruby above is itself somewhat contrived, > but... still, you wouldn't normally do something like this in Perl > whereas in Ruby, these sorts of things are actually useful. Well, I would do: puts ["tic", "tac", "toe"] or puts %w{ tic tac toe } but I know you meant it just as an illustration of yield :-) (But still it's always a pleasure to see how compact and clean Ruby can be.) > ## My favorite "Rubyism" I use all the time in Perl -- puts()! > > sub puts { for (@_) { print "$_\n" } } A perhaps slightly pedantic point: this isn't what puts actually does. It adds a "\n" to the end of the string only if one isn't there already. David -- David A. Black dblack@wobblini.net