#! perl -slw use strict; use vars qw[ $a $b ]; use List::Util qw[ reduce ]; my $op = shift @ARGV; my @hasharray; for ( 2 .. @ARGV ) { for my $indices ( Cnr( $_, 0..$#ARGV ) ) { push @hasharray, { LIST=> [ @$indices ], VALUE=> reduce{ my $val = eval "$a $op $b"; } @ARGV[ @$indices ] }; } } print "@{ $_->{LIST} } : $_->{VALUE}" for @hasharray; exit; sub Cnr{ my( $n, @r ) = shift; return [] unless $n--; for my $x ( 0 .. ($#_ - $n) ) { push @r, map{ [ $_[$x], @$_ ] } Cnr( $n, @_[ ($x+1) .. $#_ ] ) ; } return @r; } #### P:\test>283241 + 1 2 3 4 0 1 : 3 0 2 : 4 0 3 : 5 1 2 : 5 1 3 : 6 2 3 : 7 0 1 2 : 6 0 1 3 : 7 0 2 3 : 8 1 2 3 : 9 0 1 2 3 : 10 P:\test>283241 - 1 2 3 4 0 1 : -1 0 2 : -2 0 3 : -3 1 2 : -1 1 3 : -2 2 3 : -1 0 1 2 : -4 0 1 3 : -5 0 2 3 : -6 1 2 3 : -5 0 1 2 3 : -8 P:\test>283241 * 1 2 3 4 0 1 : 2 0 2 : 3 0 3 : 4 1 2 : 6 1 3 : 8 2 3 : 12 0 1 2 : 6 0 1 3 : 8 0 2 3 : 12 1 2 3 : 24 0 1 2 3 : 24 P:\test>283241 / 1 2 3 4 0 1 : 0.5 0 2 : 0.333333333333333 0 3 : 0.25 1 2 : 0.666666666666667 1 3 : 0.5 2 3 : 0.75 0 1 2 : 0.166666666666667 0 1 3 : 0.125 0 2 3 : 0.0833333333333332 1 2 3 : 0.166666666666667 0 1 2 3 : 0.0416666666666667