in reply to Re: 2D array ALL combinations
in thread 2D array ALL combinations

ikegami,

The elements '' (AoA1[1][2], AoA1[2][2], AoA1[3][1] and AoA1[3][2]) refer to empty elements. I would like combinations to exclude the empty ones to be more productive (my AoA1 is big).

Thanks for hints, best.

Replies are listed 'Best First'.
Re^3: 2D array ALL combinations
by ikegami (Patriarch) on Jun 13, 2007 at 20:15 UTC

    You could make a copy of AoA1 with them grepped out.

    my @cleaned_AoA1 = map { grep length, @$_ } @AoA1;

    If you don't mind being destructive, you could remove the blank elements from @AoA1.

    foreach (@AoA1) { @$_ = grep length, @$_; }

    I'm afraid that's the best NestedLoops can do because it can't loop using iterators.

    Grepping them out on the fly won't save you any memory.

    sub make_scrubber { my ($aref) = @_; return sub { [ grep length, @$aref ] }; } my $iter = NestedLoops( [ map { make_scrubber($_) } @AoA1 ] );