I assume you want to declare $a beforehand but not use its value in sort. If that is the case, you could declare a local sub before $a:
local *_sort = sub { return sort { $a <=> $b } @_ }; my $a = 'whatever'; print join(' ', &_sort(@arr2)), "\n";
But obviously it would be easier to just use a different variable name...
Update: I just read up on $a and $b in perlvar:
Special package variables when using sort(), see sort. Because of this specialness $a and $b don't need to be declared (using use vars, or our()) even when using the strict 'vars' pragma. Don't lexicalize them with my $a or my $b if you want to be able to use them in the sort() comparison block or function.
In reply to Re: my $a outside sort block incompatibility
by hbm
in thread my $a outside sort block incompatibility
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |