in reply to Convert hash into an array based matrix
Uses arbitrary order, which could be sorted, or even two different orders:
>perl -wMstrict -le "use Test::More 'no_plan'; use Test::NoWarnings; ;; my %HoH = ( A => { A => '1', B => '4', C => '2', }, B => { A => '4', B => '10', C => '3', }, C => { A => '2', B => '3', C => '9', }, ); ;; my @order1 = my @order2 = ('A' .. 'C'); ;; my @ra = map [ @{ $HoH{$_} }{ @order1 } ], @order2; ;; my @array = ( [1, 4, 2], [4, 10, 3], [2, 3, 9]); ;; is_deeply \@ra, \@array; " ok 1 ok 2 - no warnings 1..2
Update: Changed example code to show use of separate orders.
|
|---|