in reply to Array looping advice
When you need loops nested arbitrarily deep, think of Algorithm::Loops's NestedLoops.
If you just need the transformed values:
use Algorithm::Loops qw( NestedLoops ); my $i = NestedLoops(\@arr); while (my @vals = $i->()) { print(join(' ', @vals), "\n"); }
If you need the indexes and transformed values:
use Algorithm::Loops qw( NestedLoops ); my $i = NestedLoops([ map { [ 0..$#$_ ] } @arr ]); while (my @idx = $i->()) { my @vals = map { $arr[$_][$idx[$_]] } 0..$#idx; print('(', join(',', @idx), ') --> ', join(' ', @vals), "\n"); }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Array looping advice
by nineam (Initiate) on Aug 11, 2008 at 09:15 UTC |