can you rephrase the question?..difficult to tell if you're after a dispatch table OR a sort if and only if a condition is met OR if you're attempting to change sorting operation mid-stream OR something else. Perhaps a bit more context/wrapper for the code would exemplify what you're after.
the hardest line to type correctly is: stty erase ^H