in reply to Creating a Dynamic Nested Loops for HoA

This looks like you just want all combinations of the arrays. You can join all your arrays using recursion and then use Math::Combinatorics to get the desired output from your example.


here's a quick script I wrote to get the output from your example.
use Math::Combinatorics; my $HoA = { 'key1' => [ 1, 2, 3, 4 ], 'key2' => [ 10, 20, 30 ], 'key3' => [ 100, 200, 300 ], }; sub joinall { my $this = shift; my @ret; if (ref $this eq 'HASH') { for (keys %$this) { push @ret, joinall($this->{$_}); } }elsif (ref $this eq 'ARRAY') { for (@$this) { push @ret, joinall($_); } } else { push @ret, $this; } @ret; } @a = joinall($HoA); my $c = Math::Combinatorics->new(count => 3, data => [sort{$a <=> $b} +@a]); while (my @c = $c->next_combination) { next if length $c[0] == length $c[1] || length $c[1] == length $c[ +2] || length $c[0] == length $c[2]; print join(' - ',@c)."\n"; }