You're right, ik, the code will not work as the OP claims. @_ does not get set when _DBsort4create is called by sort; it's left holding the argument list of the sub that called sort.
sub compare { my $x = shift; print "\$a = $a, \$b = $b, \$x = $x, \@_ = @_\n"; $a cmp $b; } sub test { sort compare 'z','a','b' } my @z = test('foo', 'bar', 'baz'); print "\@z = @z\n"; output: $a = z, $b = a, $x = foo, @_ = bar baz $a = a, $b = b, $x = bar, @_ = baz $a = b, $b = z, $x = baz, @_ = @z = a b z
In reply to Re^2: Sort mechanics problems with objects and potentially contradicting comparisons (would cause infinite loop)
by Anonymous Monk
in thread Sort mechanics problems with objects and potentially contradicting comparisons (would cause infinite loop)
by anonymized user 468275
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |