in reply to Re: Sorting on Exists
in thread Sorting on Exists

Assuming a recent version of Perl, I think your original code would work if the first sort were:
sort { (exists $a->{vtype_ug}||0) <=> (exists $b->{vtype_ug}||0) }
You've got the compare function giving the opposite result than desired, but yes, it does work (in 5.8.8, at least), with this code:
@sorted = sort { (exists $b->{vtype_ug}||0) <=> (exists $a->{vtype_ug} +||0) } sort { $a->{total_rate} <=> $b->{total_rate} } @arr;
Actually, there's no need for that || 0 as exists returns a boolean, thus, that's safe to use as 0 when it returns false. So the next works too, without any warnings:
@sorted = sort { exists $b->{vtype_ug} <=> exists $a->{vtype_ug} } sort { $a->{total_rate} <=> $b->{total_rate} } @arr;