How about this?

#! 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; }

Supply the (binary) operator as the first argument, the rest will be used as the values in the array.

A few runs

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

Examine what is said, not who speaks.
"Efficiency is intelligent laziness." -David Dunham
"When I'm working on a problem, I never think about beauty. I think only how to solve the problem. But when I have finished, if the solution is not beautiful, I know it is wrong." -Richard Buckminster Fuller
If I understand your problem, I can solve it! Of course, the same can be said for you.


In reply to Re: array problems by BrowserUk
in thread array problems by bfish

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.