in reply to Converting Arrays into Matrix

It looks like just two passes through a 2D array to me, which can be factorised into one pass through the outer dimension:
my @TwoD = ( ['A','B','C'], ['A','D','C'], ['A','B','C'] ); my ( $slotH, %slotH ) = (-1,()); my @result = (); for ( my $i1 = 0; $i1 <= $#TwoD; $i1++ ) { for ( my $i2 = 0; $i2 <= $#{ $TwoD[ $i1 ]}; $i2++ ) { my $v = $TwoD[ $i1 ][ $i2 ]; defined( $slotH{ $v } ) or $slotH{ $v } = ++$slotH; $result[$i1][$slotH{ $v }] = $v; } for ( my $i2 = 0; $i2 <= $slotH; $i2++ ) { $i2 and print "\t"; print ( $result[$i1][$i2] || '' ); } print "\n"; }
produces
A B C A C D A B C
Update: actually my version needs its output rotating 90 degrees to get exactly the same output, but the technique is similar for doing that, resulting in minor change to the above script.

One world, one people