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} }
In reply to Sorting on Exists by ropey
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |