askc> our $a;
askc> my $b;
askc> $a = 'foo';
askc> $b = 'bar';
askc> my @sorted = sort { $a <=> $b } (1, 5, 7, 6, 2, 3);
askc> Can't use "my $b" in sort comparison at sor.pl line 11.
askc> our $a;
askc> my $b;
askc> $a = 'foo';
askc> $b = 'bar';
askc> my @sorted = sort { int($a) <=> int($b) } (1, 5, 7, 6, 2, 3);
askc> print $a, $b, "\n";
askc> I see a warning (but the proper output):
askc> Argument "bar" isn't numeric in int at sor.pl line 11.
askc> foobar
and the other way is also an issue. $a and $b are immune to strict
warnings since they are global and used by sort(). requiring them to be
declared in sort callback subs and such would be a pain.
perl -Mstrict -e '$a = $b'
perl -Mstrict -e '$a = $c'
Global symbol "$c" requires explicit package name at -e line 1.
so for both the global nature of $a and $b and for being immune to
strict, it is not a good idea to use those vars outside sort code.
uri