Hello --

On Sun, 21 Oct 2001, Michael Neumann wrote:

> David Alan Black wrote:
> >
> > > $ 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'
> >
>
> Using the -n (or -p) option, you can ommit the while-loop:
>
>   $ ruby -ne 'puts /^\d/ ? "Starts with digit" : "Nope"'
>
> With -p option (prints out $_ in each iteration):
>
>   $ ruby -pe '$_ = /^\d/ ? "Starts with digit" : "Nope"'

Interesting!  At first I thought the = was supposed to be =~, but now
I get it :-)

The only thing is that you'd need an 'l' switch in there too (or stick
\n's on the strings).)


David

-- 
David Alan Black
home: dblack / candle.superlink.net
work: blackdav / shu.edu
Web:  http://pirate.shu.edu/~blackdav