> >> You do know that for and foreach are exact synonyms?
> > 
> > And that $_ is the default variable for //, so the '$_ =~' can
> > be deleted?  The straightforward golfish translation for your
> > program is something like
> > 
> >   print,/Dr /&&last for@names
> 
> 27 strokes.
> 
> for (@names){print;last if /Dr /;}
> 
> 34 strokes.
> 
> Not to bad :)
> Was over 50 strokes :)

Here is another:

> for (@names){print;last if /Dr /;}
     ^                   ^^^^     ^
     Bye bye whitespace    |      \-- The last semicolon in
                           |          a block can be omitted
                           \- if can often be replaced by &&

which is then:

for(@names){print;last if /Dr /}

before working on the 'if'...

Now, the 'if' means:

Do STATEMENT if CONDITION

which is the same as:

CONDITION && STATEMENT

because the right hand side is only evaluated if the left
side is true.  See page 26-27 of Programming Perl (3rd ed)
for details.

Hence, if you follow you can reduce to:

for(@names){print;/Dr /&&last}

And you've probably got enough skills to push yourself
into a reasonable spot on the beginners board.  Remember,
those high ranking veterans sacrificed their sanity upon
the holy altar, and in return they received Perly wisdom
and dirty secrets about Perl.


> I foresee the future containing 'Perl Golf training
> sessions' such as this :)

Whatever it takes!  Perl golf will assimilate all mankind,
all races, cultures and creeds.  We are the enslaved agents
of Larry's twisted game, and therefore will assist in any
way possible... and taking however long it takes to add you
to the collective :P 

Jonathan Paton

__________________________________________________
Do You Yahoo!?
Everything you'll ever need on one web page
from News and Sport to Email and Music Charts
http://uk.my.yahoo.com

Reply via email to