Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re^2: Printing from three arrays

by daxim (Curate)
on Sep 26, 2019 at 10:37 UTC ( #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
Node Status?
node history
Node Type: note [id://11106739]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others chanting in the Monastery: (7)
As of 2020-09-26 21:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    If at first I donít succeed, I Ö










    Results (142 votes). Check out past polls.

    Notices?