From: ptkwt@... (Phil Tomson) Date: 2005-08-11T10:06:11+09:00 Subject: Re: anonym variable $_ and foreach similar in Ruby ? In article <1123703873.374539.125830@g47g2000cwa.googlegroups.com>, Charles Steinman wrote: > >ngoc wrote: >> Hi >> 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. In addition, it looks a >> little bit complicated in Ruby. I think in THIS CASE perl is more >> elegant than Ruby? >> >> Is it a right thinking (IN THIS CASE)? >> Are there other ways than those two array.each? > >There is also > >----code--- >for e in array; puts e end >----endcode--- > > and for the original poster who seemed to prefer: print $_, "\n" foreach (@array); (for whatever reason) He could even say: puts for item in array; end If he really wanted to ;-) ....of course it would be much shorter to just say: puts array Phil