Thread Sort Array of Hashes by Key
(7 answers)
Opened by devrand at 2012-09-18 21:12
Hallo zusammen,
folgende Datenstruktur moechte ich nach den Keys (ZLANED, E3000E, IWWAST, UXWAGL) alphabetisch sortieren: Code (perl): (dl
)
1 2 3 4 5 6 7 8 my @unsorted = ( { 'ZLANED' => [ { 'CO' => 'AAA' }, { 'AT' => 'AA' } ] }, { 'E3000E' => [ { 'CO' => '123' }, { 'AT' => '00' } ] }, { 'IWWAST' => [ { 'CO' => 'ABC' }, { 'AT' => 'AA' } ] }, { 'UXWAGL' => [ { 'CO' => 'ABC' }, { 'AT' => 'EF' } ] }, { 'E3000E' => [ { 'CO' => '123' }, { 'AT' => 'CC' } ] }, { 'IWWAST' => [ { 'CO' => 'AAA' }, { 'AT' => 'AB' } ] }, ); Ergebnis: Code (perl): (dl
)
1 2 3 4 5 6 7 8 my @sorted = ( { 'E3000E' => [ { 'CO' => '123' }, { 'AT' => '00' } ] }, { 'E3000E' => [ { 'CO' => '123' }, { 'AT' => 'CC' } ] }, { 'IWWAST' => [ { 'CO' => 'ABC' }, { 'AT' => 'AA' } ] }, { 'IWWAST' => [ { 'CO' => 'AAA' }, { 'AT' => 'AB' } ] }, { 'UXWAGL' => [ { 'CO' => 'ABC' }, { 'AT' => 'EF' } ] }, { 'ZLANED' => [ { 'CO' => 'AAA' }, { 'AT' => 'AA' } ] }, ); Ich habe mich in sort (cmp) bzw. map schon eingelesen, aber ich checks nicht... Danke! Last edited: 2012-09-18 21:32:07 +0200 (CEST) |