ropey has asked for the wisdom of the Perl Monks concerning the following question:
Hi, This is probably going to be simple... mind not working today..
So I have have a array of hash references, firstly I want to sort it on price order and then I want to sort it dependent on having a particular key.. So lets say I have this
I want it to be sorted like[ { 'vtype_ug' => 1 + 'total_rate' => 400, }, { 'total_rate' => 220, }, { 'total_rate' => 700, 'vtype_ug' => 1, }, { 'total_rate' => 300, }, { 'total_rate' => 400, }, { 'total_rate' => 250, }, ]
I tried this... it almost works but not quite...[ { 'vtype_ug' => 1 + 'total_rate' => 400, }, { 'total_rate' => 700, 'vtype_ug' => 1, }, { 'total_rate' => 220, }, { 'total_rate' => 250, }, { 'total_rate' => 300, }, { 'total_rate' => 400, }, ]
I know its probably just my little brain not working very well.. but any help appreciated.my @sorted = sort { (exists $a->{vtype_ug}) ? -1 : 0} sort { $a->{total_rate} <=> $b->{total_rate} }
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: Sorting on Exists
by davorg (Chancellor) on Sep 08, 2006 at 10:13 UTC | |
by bart (Canon) on Sep 09, 2006 at 20:16 UTC | |
Re: Sorting on Exists
by holli (Abbot) on Sep 08, 2006 at 09:18 UTC | |
Re: Sorting on Exists
by artist (Parson) on Sep 08, 2006 at 11:25 UTC | |
by holli (Abbot) on Sep 08, 2006 at 20:09 UTC | |
Re: Sorting on Exists
by sgifford (Prior) on Sep 08, 2006 at 16:14 UTC | |
by bart (Canon) on Sep 09, 2006 at 20:18 UTC |