in reply to Complex conditional sort
my @list = map {substr($_, 1)} sort map {$lookup{$_}{val} > 0 ? "A$_" : "B$_"} @list;
Update: You asked if this could be done without breaking out of a sort block because you would be choosing the block from a hash. You could just as easily use a subroutine instead of a sort block but you could do the same trick in the block itself:
sort { my $lhs = $lookup{$a}{val} > 0 ? "A$a" : "B$a"; my $rhs = $lookup{$b}{val} > 0 ? "A$b" : "B$b"; $lhs cmp $rhs }
Cheers - L~R
|
|---|