in reply to my $a outside sort block incompatibility
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: my $a outside sort block incompatibility
by Anonymous Monk on Feb 21, 2009 at 01:43 UTC |