Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:
I want to sort the above array of hashes based on multiple keys in hashes. i.e., If I do a sort as key1-ASC, key2-DSC, the output of the above array should be like this@array = ( {'key1' ==> 'abc', 'key2' ==> '111', 'key3' ==> 'abcdef'}, {'key1' ==> 'acc', 'key2' ==> '101', 'key3' ==> 'abcdef'}, {'key1' ==> 'acc', 'key2' ==> '1000', 'key3' ==> 'abcdef'}, {'key1' ==> 'abc', 'key2' ==> '112', 'key3' ==> 'abcdef'} )
Hope the above illustration is understandable. This kind of multi-column sorting is already available in MsExcel. i.e., if we have data in 2 columns and then sort them by specifying - "sort first column in ascending" and "sort second column in descending", it will give the above output. Please let know, if this can be done in PERL. Thanks in advance. Mani.{'key1' ==> 'abc', 'key2' ==> '112', 'key3' ==> 'abcdef'}, {'key1' ==> 'abc', 'key2' ==> '111', 'key3' ==> 'abcdef'}, {'key1' ==> 'acc', 'key2' ==> '1000', 'key3' ==> 'abcdef'}, {'key1' ==> 'acc', 'key2' ==> '101', 'key3' ==> 'abcdef'}
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: MsExcel like Multi Column Sorting
by davorg (Chancellor) on Dec 01, 2006 at 11:27 UTC | |
by bart (Canon) on Dec 01, 2006 at 12:23 UTC | |
|