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

Re: [FWP] Cartesian Cross-Products in one <80 char line



On Mon, 17 Apr 2000, David L. Nicol wrote:

> perl
> -lane'BEGIN{@r=[]}END{print"@$_"for@r}@r=map{$f=$_;map{[@$_,$f]}@r}@F'

Let's lower the golf score a bit:

  perl -pale'@r=map{$f=$_;map[@$_,$f],@r?@r:[]}@F}for(@r){$_="@$_"'

The BEGIN block gets replaced by the conditional ( @r?@r:[] ).  The -n
switch changes to -p, so that the END block can be replaced with inverted
braces ( }for(@r){ ).  And changing the inner map BLOCK to map EXPR saves
one extra character.

Hope that actually works. :)

-- 
Neko



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