in reply to Problem with Schwartzian Transform nested in another sort from a different package
Just have your sort functions declared with a prototype of ($$) and it will pass data in through @_ and never use $a or $b. (Avoiding confusion about what package $a and $b are to be found in.) That is write:
(Should work in 5.6 on up.)sub mycmp ($$) { my ($first, $second) = @_; return 1 if $first ne ( mysort($first, $second) ); return -1 if $first eq ( mysort($second, $first) ); return 0; } # and elsewhere ... sort {&Whatever::Package::mycmp} map ... # or put in in a variable my $cmp = \&Whatever::Package::mycmp; ... sort $cmp map ... # of if you don't mind a speed hit and don't trust the user my $cmp = sub ($$) {Whatever::Package::mycmp(@_)}; ... sort $cmp map ...
Incidentally coding a cmp function in terms of a sort function strikes me as both obscure and inefficient.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Problem with Schwartzian Transform nested in another sort from a different package
by ronald (Beadle) on Apr 15, 2004 at 23:15 UTC |