[Date Prev][Date Next][Thread Prev][Thread Next] [Search] [Date Index] [Thread Index]

Re: fifth word (was Re: [FWP] Fun With Golf)



On Wed, Oct 18, 2000 at 11:40:42AM -0400, Steve Lane wrote:
> >   sub fifth_word {my$a=pop;s/(\w+)// for 1..5;$1}
> >             start^                              ^end
> 
> that doesn't work, and s/my\$a/\$_/ won't fix it.  
> here's my first try:
> 
>     sub fifth_word {$_=pop;s/^\W+//;(split/\W+/)[4]}

How about

      sub fifth_word {$_=pop;/(\w+\W*){4}(\w+)/;$2}

a couple of chars shorter,

Fergal

==== Want to unsubscribe from Fun With Perl?  Well, if you insist...
==== Send email to <fwp-request@technofile.org> with message _body_
====   unsubscribe