P is for Practical | |
PerlMonks |
How to get sort-like semantics?by b4swine (Pilgrim) |
on Oct 25, 2007 at 12:21 UTC ( [id://647153]=perlquestion: print w/replies, xml ) | Need Help?? |
b4swine has asked for the wisdom of the Perl Monks concerning the following question:
I was trying to learn prototypes, so decided to make a reduce function as follows.
It works. My question is how can I get it to have semantics exactly like sort? Update: Since there seems to be some confusion as to what I meant by this question, let me elaborate from the documentation about sort: If the subroutine's prototype is ($$), the elements to be compared are passed by reference in @_, as for a normal subroutine. This is slower than unprototyped subroutines, where the elements to be compared are passed into the subroutine as the package global variables $a and $b. SUBNAME may be a scalar variable name (unsubscripted), in which case the value provides the name of (or a reference to) the actual subroutine to use. moritz and duelafn seem to have addressed most of the issues.
Back to
Seekers of Perl Wisdom
|
|