in reply to Permutations question

Here is a solution based on tye's Algorithm::Loops:
use Algorithm::Loops qw( NestedLoops ); my $iter= NestedLoops( [ [1], [ 2, 3, 4 ], [5], [ 6, 7, 8 ], [9] ], ); my @perms; while( @perms = $iter->() ) { print @perms, "\n"; }

-Mark

Replies are listed 'Best First'.
Re^2: Permutations question (non-iter)
by tye (Sage) on Feb 22, 2005 at 17:25 UTC

    Or, if we want to exactly match the original request, it is easy to transform to:

    use Algorithm::Loops qw( NestedLoops ); sub expandSubLists { my $av= shift(@_); return [ NestedLoops( [ map ref($_) ? $_ : [$_], @$av ], sub { [@_] }, ), ]; }

    which, of course, chews up a lot of memory if given a lot of selections to generate.

    - tye