From: ChrisO Date: 2004-09-16T07:55:14+09:00 Subject: Re: Ex-Perl coders: Howz it feel to convert to Ruby? David A. Black wrote: > 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 :-) Yep! (But > still it's always a pleasure to see how compact and clean Ruby can > be.) Yep (again). > > >>## 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. > You know, I didn't discover that until this week on my re-entry into Ruby... But I'd say 95% of the time I use puts in Ruby, it's without the "\n" at the end, so in Perl I like having the same behavior. -ceo