No. Your my-declaration had the problem that you changed
$a and $b to lexical variables, so when the sort function
was setting the globals $a and $b, the function
looked at the wrong variables.
Let us not mention the fact that your example assumed that
the data never would include false values...