in reply to Why do we need $a and $b to be special?

IIRC, the original reason for $a and $b is that they were much faster then using @_. That's less true then it used to be, but it's still the case that most sort routines are trivial enough that writing $_[0] and $_[1] instead of $a and $b makes them significantly more complex-looking.

In any case, as you say, they'll be gone in perl6. They aren't going away in perl5, because it'd instantly break everybody's code.


Warning: Unless otherwise stated, code is untested. Do not use without understanding. Code is posted in the hopes it is useful, but without warranty. All copyrights are relinquished into the public domain unless otherwise stated. I am not an angel. I am capable of error, and err on a fairly regular basis. If I made a mistake, please let me know (such as by replying to this node).

Replies are listed 'Best First'.
Re^2: Why do we need $a and $b to be special?
by ambrus (Abbot) on Jul 30, 2004 at 12:26 UTC
    IIRC, the original reason for $a and $b is that they were much faster then using @_.

    I thought the original reason was that sort with a block was in perl4 and there were no subroutines at that time, but I might be wrong.

      Even Perl 1 had subroutines. I don't have time to look at how sort worked then, but I do remember having to say somethign like do &subname to make subroutine calls in Perl 1.

      Of course, now that I post, I immediately realize you probably meant didn't have lexicals, which is true.