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

Re: [FWP] Perl Card Games



John Porter wrote:
> 
> >   JP> $handsize = 5; # straight poker.
> >   JP> @hands = 5;    # O.k., who's in?
> >   JP> @$_ = splice @deck, 0, $handsize  for @hands;  # too much fun.

> I meant something more like
> 
>         @hands = () x 5;

Something like?  :-)

    @hands = ( () x 5 ) x 5;# ?
    @hands = ( ( () x 5 ) x 5 ) x 5;# ? 
    ...

Maybe you meant something more like

    @hands = ( [] ) x 5;
?

But then all the hands will be the same.  :-(

Of course you meant

    @hands = (undef) x 5;

Viva la autovivification!
 
> But later I realized I could just do
> 
>         $n_hands = 5;
>         @hands = map [splice @deck,0,$handsize], 1..$n_hands;
> 
> But I don't think that's as fun as
> 
>         @$_ = (...) for @hands;

Agreed.  One more (fun) way of initializing @hands:

    ($#hands = 5)--;

-- 
Rick Delaney
rick.delaney@home.com

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