Chris Olive <colive / technologEase.com> writes:

> I can't seem to find the Ruby syntax that is equivalent to the following
> in Perl:
> 
> while (<>) { DoAnyThing( $_ ) }

ARGF.each { |l| DoAnything(l) }      

ARGF is a special object providing an API like a File object, but
iterates over all files on the command line (or stdin).

> <snip> ... I can just type in the line, and test at the command
> line:
> 
> $ perl -e 'while (<>) { if (/^\d/) { print "Starts with digit\n" } else
> { print "Nope\n" } }'
> 123
> Starts with digit
> Hey!
> Nope
> ^D
>
> How can I do the same in Ruby?  There's got to be a way!

In addition to what David Alan Black suggested, there is the very
explicit:

ruby -e 'ARGF.each { |l| if l =~ /^\d/ then puts "Starts with digit" \
     else puts "Nope" end }'



-- 
matt