From: David Alan Black Date: 2001-10-21T12:48:42+09:00 Subject: [ruby-talk:22861] Re: Newbie: Ruby equiv for Perl while (<>)??? Hello -- On Sun, 21 Oct 2001, Chris Olive wrote: > I just learned about Ruby two days ago, and spent all day Friday > learning it. It's TOTALLY KILLER... I thought I liked Perl... WOW. > This has me swimming. Not to mention that I've never really soaked > myself into anything OO -- no time. Well, I made the time, and this is > awesome. I'm already extending base classes for some really elegant and > quick solutions... OO is cool too. > > Anyway, enough of the accolades, well deserved though they are. Way to > go Matz... Welcome to Ruby! I had just about exactly the same experience, just about exactly a year ago. And I'm here to tell you that, a year later, it's still an awesome language. > $ perl -e 'while (<>) { if (/^\d/) { print "Starts with digit\n" } else > { print "Nope\n" } }' You could do: $ ruby -we 'while gets; puts(/^\d/ && "Starts with digit" || "Nope"); end' or if you want to give your fingers more exercise (and see a couple of other little Ruby things in action): $ ruby -we 'while gets; puts begin if /^\d/ then "Starts with digit" \ else "Nope" end end end' You could also use the ternary operator ( a? b : c), but personally I always think that looks like C or Perl being written in Ruby. David -- David Alan Black home: dblack@candle.superlink.net work: blackdav@shu.edu Web: http://pirate.shu.edu/~blackdav