http://www.perlmonks.org?node_id=1137636


in reply to Re: question about: my $a AND sort {$a <=> $b} keys %hash
in thread question about: my $a AND sort {$a <=> $b} keys %hash

Don't lexicalize them with my $a or my $b if you want to be able to us +e them in the sort() comparison block or function.
But, on the other hand you can localize them when needed:
$ perl -we ' local $a = 1; @h = sort {$a <=> $b} keys %hash; print "@h\n";> %hash = map { $_ , undef } 0 .. 3; @h = sort {$a <=> $b} keys %hash; print "@h\n"; ' 0 1 2 3