Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 3661330
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 19, 20262026-05-19T01:17:37+00:00 2026-05-19T01:17:37+00:00

tell me how to get every possible combination of hash Here is an example

  • 0

tell me how to get every possible combination of hash

Here is an example

my %data = (
'a' => [qw(a1 a2 a3)],
'b' => [qw(b1 b2 b3)],
'c' => [qw(c1 c2 c3)]);

to get

a1
a2
a3
b1
b2
b3
c1
c2
c3

a1 b1
a1 b2
a1 b3
a1 c1
a1 c2
a1 c3

b1 c1
b1 c2
b1 c3
b2 c1
b2 c2
b2 c3
b3 c1
b3 c2
b3 c3

a1 b1 c1
a1 b1 c2
a1 b1 c3
a1 b2 c1
a1 b2 c2
a1 b2 c3
a1 b3 c1
a1 b3 c2
a1 b3 c3
a2 b1 c1
a2 b1 c2
a2 b1 c3
a2 b2 c1
a2 b2 c2
a2 b2 c3
a2 b3 c1
a2 b3 c2
a2 b3 c3
a3 b1 c1
a3 b1 c2
a3 b1 c3
a3 b2 c1
a3 b2 c2
a3 b2 c3
a3 b3 c1
a3 b3 c2
a3 b3 c3

thanks

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-19T01:17:38+00:00Added an answer on May 19, 2026 at 1:17 am

    My module List::Gen contains a cartesian function that can produce the results you want. This code seems to do the trick, but your example does not contain all of the permutations that this will produce, which I am assuming is just an omission in the example.

    use List::Gen 'cartesian';
    
    my %data = (
        'a' => [qw(a1 a2 a3)],
        'b' => [qw(b1 b2 b3)],
        'c' => [qw(c1 c2 c3)],
    );
    
    my $product = cartesian {join ' ' => sort grep defined, @_}
                  map {[@$_, undef]} 
                  values %data;
    
    say for sort {length $a <=> length $b or $a cmp $b} @$product;
    

    That is a bit dense, so to explain:

    • values %data returns the arrays in %data
    • map {[@$_, undef]} then attaches an empty value to the end of each, since you want the partial combinations
    • cartesian {join ' ' => sort grep defined, @_} then does the meat of the work, computing the Cartesian product of the arrays while subtracting out the undefined elements, and sorting the values as your example shows.
    • sort {length $a <=> length $b or $a cmp $b} @$product then prints out the product in the order specified.
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Can somebody please tell me how I can get google analytics on every page
please tell me how to get and bind data to UltraGrid dynamically on each
Could someone tell if it's possible to get an OpenCL code working with both
Is there a way to tell how to get a file size that is
Please tell me how can I get array of all Those DIV of specific
Can anyone tell me how to get remote Sqlserver instances using c# and SMO
Can someone tell me why I get the null value for activationLink variable in
Can someone tell me how can I get MS Entity Framework working with PostgreSQL.
Can anyone tell me how to get and display the biggest values from a
can any one please tell me how to get the Google places api key

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.