M
Matt Garrish
Peter J. Holzer said:What version of perl are you using? perl 5.8.4 doesn't even compile the
program if you try to use sort inside a block with lexicals $a or $b:
my @x = qw(12 8 4 23 42 17 3);
my $a = 5;
my $b = 6;
my @y = sort {$a <=> $b} @x;
print "@y\n";
% perl foo2
Can't use "my $a" in sort comparison at foo2 line 5.
It depends on whether you declare $a and $b before or after the sort:
my @x = qw(12 8 4 23 42 17 3);
my @y = sort {$a <=> $b} @x;
my $a = 5;
my $b = 6;
print "@y\n";
% perl foo2
3 4 8 12 17 23 42
In this fellow's case, that's what I suspect he did, so it didn't affect his
sort but put his comparison into an endless loop.
Matt