Once Ran Eilam has showed me the following:
print Dumper combs(
[qw(a b)],
[qw(foo bar baz)],
[qw(one two)]
);
sub combs {
return ([]) if !scalar(@_);
my $atoms = shift;
map
{ $tuple = $_; map [$_, @{$tuple}], @{$atoms} }
combs(@_);
}
------------------------
Exlanation:
Assume we have combs(N-1 lists) working, just need to compute combs(N).
combs(N) = combs(N-1) X [the 1st list]
Where X is cartesian multiplication- the inner map above.
--Eitan
On 8/20/07, Peter Gordon <[EMAIL PROTECTED]> wrote:
> On Mon, 2007-08-20 at 09:32 +0300, Gaal Yahas wrote:
> > On 8/20/07, Peter Gordon <[EMAIL PROTECTED]> wrote:
> > > I have a number of arrays
> > [...]
> > > and I want to find all possible combinations of all elements
> > [...]
> > > Is there a package which iterates over arrays?
> >
> > You mean you don't know in advance how many arrays you have (or just
> > want to factor out the nestedness in your code)?
>
> The number of arrays varies with each iteration
>
>
>
> > Take a look at
> > Algorithm::Loops, specifically at the "Nested loops" stuff.
> >
>
_______________________________________________
Perl mailing list
[email protected]
http://perl.org.il/mailman/listinfo/perl