Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re^2: sort of misunderstanding of sort

by LanX (Saint)
on Mar 21, 2023 at 11:51 UTC ( [id://11151096]=note: print w/replies, xml ) Need Help??


in reply to Re: sort of misunderstanding of sort
in thread sort of misunderstanding of sort

> I assume you want the cross-product

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

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://11151096]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others romping around the Monastery: (3)
As of 2024-04-25 17:25 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found