Sigue el código:
lhp@nereida:~/Lperl/src$ cat -n allsubsets.pl 1 #!/usr/bin/perl -w 2 use strict; 3 4 sub subsets { 5 my @set = @_; 6 my $powern = 1 << @set; 7 my $n = -1; 8 9 my $s = sub { 10 $n++; 11 return map { $n & (1 << $_)? ($set[$_]) : () } 0..$#set; 12 }; 13 14 return $s; 15 } 16 17 die "$0 el1 el2 el3 ...\n" unless @ARGV; 18 my $s = subsets(@ARGV); 19 20 my @S; 21 FOREVER: { 22 @S = $s->(); 23 24 local $" = ', '; 25 print "(@S)\n"; 26 27 last if (@S == @ARGV); 28 29 redo FOREVER; 30 }
Casiano Rodríguez León