To add to what
blokhead said, you need to make sure your sort routine is using the global (package) $a and $b instead of the lexical (my) $a and $b. You can do this several ways:
- qualify as $::a and $::b in the sort. (Variables with :: are always globals; the empty package name is a synonym for the main package; If your sort() call is in package Foo, use $Foo::a and $Foo::b instead.)
- restrict the scope of your lexical $a and $b to not include the sort.
- put an our $a; our $b; before the sort. This will hide the lexicals until the end of the enclosing block. You can even put the our statements at the beginning of the sort routine (whether inline or not); this will cause a very slight slowdown, though.
- rename your my $a and my $b to something else.