in reply to Re: sort of misunderstanding of sort
in thread sort of misunderstanding of sort
DB<34> sub cross (&$$) { my ($code,$list1,$list2) = @_; local ($a,$b +); my @res; for $a (@$list1) { for $b (@$list2) { push @res, &$code } +}; return @res; } DB<35> x cross { $a + $b } [0..2], [10,20,30] 0 10 1 20 2 30 3 11 4 21 5 31 6 12 7 22 8 32 DB<36>
you can just let $list2 default to $list1 if undef to have a self-operation with only one list.
$list2 //= $list1
Cheers Rolf
(addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
Wikisyntax for the Monastery
|
|---|