in reply to Sort Array of Hashes by values of multiple hash keys.
The above code sorts a lits of hashes (each hash containing first and last names) by last name and then first name. The order of the original @l is not altered.my @l=( {FN=>'Les',LN=>'Howard'}, {FN=>'Larry',LN=>'Wall'}, {FN=>'Randal',LN=>'Schwartz'}); foreach(sort {$$a{LN} cmp $$b{LN} or $$a{FN} cmp $$b{FN}} @l){ print "$$_{LN}, $$_{FN}\n"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
RE: Sort Array of Hashes by values of multiple hash keys.
by davorg (Chancellor) on Jun 21, 2000 at 13:04 UTC | |
|
RE: RE: Sort Array of Hashes by values of multiple hash keys.
by raflach (Pilgrim) on Jun 19, 2000 at 19:49 UTC |