×
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Are you a
Computer / IT professional?
Join Tek-Tips Forums!
• Talk With Other Members
• Be Notified Of Responses
• Keyword Search
Favorite Forums
• Automated Signatures
• Best Of All, It's Free!

*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

#### Posting Guidelines

Promoting, selling, recruiting, coursework and thesis posting is forbidden.

# Hi All, I wish to create array @

## Hi All, I wish to create array @

(OP)
Hi All,

I wish to create array @c from arrays @a and @b

@a = (1, 2, 3)
@b = ("a", "b");

In @c I want all values of @a with all possible combinations of @b

@c = (
[ [1,"a"], [2,"a"], [3,"a"] ]
, [ [1,"a"], [2,"a"], [3,"b"] ]
, [ [1,"a"], [2,"b"], [3,"a"] ]
, [ [1,"b"], [2,"a"], [3,"a"] ]
, [ [1,"b"], [2,"b"], [3,"a"] ]
, [ [1,"b"], [2,"b"], [3,"b"] ]
)

What would we be the best way to accomplish this?

Thanks for helping out.

Johan

### RE: Hi All, I wish to create array @

What have you tried so far?

### RE: Hi All, I wish to create array @

#### Quote (Johan De Graeve)

I want all values of @a with all possible combinations of @b

What you want seems to be variations with repetition or so called n-tuples from a set of m-elements
https://en.wikipedia.org/wiki/Tuple#n-tuples_of_m-...
In your case m = 2 and n = 3, so the number of all variations with repetition would be 23 = 8, like this:

#### CODE

[
[[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"]]
] 
To generate these data I adapted the program from here
https://stackoverflow.com/questions/2366074/code-f...
You can use it as template to write your own perl version.

#### Red Flag This Post

Please let us know here why this post is inappropriate. Reasons such as off-topic, duplicates, flames, illegal, vulgar, or students posting their homework.

#### Red Flag Submitted

Thank you for helping keep Tek-Tips Forums free from inappropriate posts.
The Tek-Tips staff will check this out and take appropriate action.

Close Box

# Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

• Talk To Other Members
• Notification Of Responses To Questions
• Favorite Forums One Click Access
• Keyword Search Of All Posts, And More...

Register now while it's still free!