From: Daniel Brockman Date: 2005-08-12T12:31:56+09:00 Subject: Re: anonym variable $_ and foreach similar in Ruby ? ngoc writes: > In perl > > print $_, "\n" foreach (@array); > > In Ruby > > array.each { |e| print e, "\n" } > > or > > array.each do |e| print e, "\n" end > > So |e| is similar to $_. But I can not say > > { |e| print e, "\n"} array.each > > because of block as argument and OO issue. The following syntax comes out naturally for Ruby, print e, "\n" for e in array but Matz does not want to allow it because he believes that referencing a variable before binding it is too confusing. > In addition, it looks a little bit complicated in Ruby. > I think in THIS CASE perl is more elegant than Ruby? Although I do loathe the forced dummy variable `e', I think you could come up with lots of better examples of where Perl code is more elegant than the equivalent Ruby. -- Daniel Brockman