On Wed, Jul 25, 2001 at 10:18:47PM -0500, David L. Nicol wrote:
> Yes, exactly.  I would like to have a transpose operator, which
> will work on a list of hash refs, so this:
> 
>       $solids = [1..7];
>       $stripes = [9..15];
>       foreach (transpose($solids,$stripes));
>               print "the $_->[0] ball is the same color as the $_->[1]\n";
>       }
> 
> will describe a pool set.
> 
> Who, on FWP, (and not CC'd elsewhere) can write the shortest/fastest?

sub transpose {
map{[$_,shift@{$_[1]}]}@{$_[0]}
}

Dependent on the lists being the same length for reasonable results.
If the first list is shorter, the latter is truncated; if the latter
is shorter, it's functionally extended to the length of the former
with undefs -- either of these is arguably the correct behavior, but
presumably you'd want the _same_ behavior in either case.

-- 
zed at-sign apricot dot com                http://www.apricot.com/~zed/
Zed Lopez                                  PO Box 12546 Berkeley CA 94712

Reply via email to