dazai has asked for the wisdom of the Perl Monks concerning the following question:

I want to generate all possible subsets of an array in perl(in any order), does anyone know how to do it ? Thanks in advance, dazai

Replies are listed 'Best First'.
Re: generating all subsets of an array
by Roy Johnson (Monsignor) on May 27, 2005 at 16:41 UTC
    Yes. Search for powerset.

    Caution: Contents may have been coded under pressure.
Re: generating all subsets of an array
by Limbic~Region (Chancellor) on May 27, 2005 at 16:56 UTC
Re: generating all subsets of an array
by Cristoforo (Curate) on May 28, 2005 at 01:06 UTC
    Algorithm::ChooseSubsets does this. The output follows __END__.
    use strict; use warnings; use Algorithm::ChooseSubsets; my @items = qw/red white blue/; my $iter = Algorithm::ChooseSubsets->new(\@items); while (my $x = $iter->next) { print "@$x\n" } __END__ C:\perlp>perl t2.pl red white blue red white red blue white blue red white blue C:\perlp>
    Chris