Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister
 
PerlMonks  

Re: Creating a Dynamic Nested Loops for HoA

by bageler (Hermit)
on Dec 06, 2005 at 17:46 UTC ( [id://514564]=note: print w/replies, xml ) Need Help??


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"; }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others having a coffee break in the Monastery: (3)
As of 2024-04-16 04:07 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found