Beefy Boxes and Bandwidth Generously Provided by pair Networks
Don't ask to ask, just ask
 
PerlMonks  

Re: combinations of multiple variables which can assume multiple values

by tybalt89 (Monsignor)
on Mar 16, 2018 at 16:42 UTC ( [id://1211060]=note: print w/replies, xml ) Need Help??


in reply to combinations of multiple variables which can assume multiple values

Did you mean?

#!/usr/bin/perl # http://perlmonks.org/?node_id=1211055 use strict; use warnings; use Data::Dump 'pp'; my @a = (1, 2, 3); my @b = ("a", "b"); my @bc = map [ split // ], glob +('{' . join(',', @b) . '}') x @a; my @c = map { my $t = $_; [ map [ $_, $t->[$_-1] ], 1..@a ] } @bc; pp @c;

Outputs:

( [[1, "a"], [2, "a"], [3, "a"]], [[1, "a"], [2, "a"], [3, "b"]], [[1, "a"], [2, "b"], [3, "a"]], [[1, "a"], [2, "b"], [3, "b"]], [[1, "b"], [2, "a"], [3, "a"]], [[1, "b"], [2, "a"], [3, "b"]], [[1, "b"], [2, "b"], [3, "a"]], [[1, "b"], [2, "b"], [3, "b"]], )

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having an uproarious good time at the Monastery: (6)
As of 2024-04-19 12:45 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found