Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: Printing from three arrays

by daxim (Curate)
on Sep 26, 2019 at 10:37 UTC ( [id://11106739]=note: print w/replies, xml ) Need Help??


in reply to Re: Printing from three arrays
in thread Printing from three arrays

Nested loops become unwieldy when you have many arrays. With a suitable module it does not matter how many dimension the input has:
use 5.010; use Set::Scalar qw(); my $iter = Set::Scalar->cartesian_product_iterator( map { Set::Scalar->new(@$_) } [1, 2, 3], [qw/a b c/], [qw/I II III/], ); while (my @m = $iter->()) { say "@m"; }
There are numerous alternatives: https://metacpan.org/search?q=cartesian+product
Bonus:
use v6; .say for cross (1, 2, 3), <a b c>, <I II III>

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (2)
As of 2024-04-20 05:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found