I used the below code to sort values and display it as a dropdown in a Perl form page And I need to display a certain value always at the top of the sorted list, how to do that?
values= [sort {$a<=>$b and $orig->{$a} cmp $orig->{$b}} keys %$orig]
I tried this too,not working with me for some reason
values= [sort {if ($a eq 'somevalue') { return 1; }
elsif ($b eq 'somevalue') { return -1; }
else { return {$a<=>$b and $orig->{$a} cmp $orig->{$b}} keys %$orig ;} }]
Any help?
You can sort
$specialvalue like the lowest using(($b eq $special) - ($a eq $special))as the first link in "sORt chain":(($b eq $special) - ($a eq $special))returns:0when $a and $b are special [$a is equal $b]-1when $a is special and $b is not [$a less than $b]+1when $b is special and $a is not [$a greater than $b]0when both $a and $b are not special [$a is equal $b]When it produces 0 next links in the sORt chain are queried.