in reply to Re^3: implicit sort disables a chained subroutine?
in thread implicit sort disables a chained subroutine?

An it wouldn't make any difference in your case whether the comparator function were passed to sort as a coderef

Hmm. I thought it would. If first parameter to sort was either a coderef or a string (constant) or bareblock, it would take it as a comparator, but if it is a bareword, then it's a (user or builtin) function that gets called and it results get passed to sort with the default comparator would be used.

That would treat user functions the same as builtins are currently treated as with split in the example I showed.

But you are right, that water passed under the bridge a long time since, and it is not going to change course now.

It surprises me that I never encoutered this before.


Examine what is said, not who speaks.
Silence betokens consent.
Love the truth but pardon error.
  • Comment on Re^4: implicit sort disables a chained subroutine?

Replies are listed 'Best First'.
Re^5: implicit sort disables a chained subroutine?
by demerphq (Chancellor) on Jan 14, 2005 at 09:39 UTC

    One interesting thing is that the behaviour of sort does change depending on the prototype of the sub being called. If it had a prototype of $$ sort would pass $a and $b in as arguments, if it has any other prototype it sets the packages $a and $b instead. Hypothetically I think it could throw an error if the prototype of the sub was (@) as that would almost certainly be DWIM getting things wrong.

    ---
    demerphq

Re^5: implicit sort disables a chained subroutine?
by Aristotle (Chancellor) on Jan 14, 2005 at 09:27 UTC

    Ah, you meant coderef vs bareword as in syntax, not semantics.

    I agree that this behaviour is surprising. I guess that goes to show it isn't that bad a special case in practice, probably because comparator blocks are used too frequently for it to matter too much. Back in Perl4 without anonymous functions and prototypes available I guess this special case was actually good.

    Makeshifts last the longest.