Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!sdd.hp.com!usc!apple!sun-barr!newstop!texsun!convex!convex.COM From: tchrist@convex.COM (Tom Christiansen) Newsgroups: comp.lang.perl Subject: Re: inlining your sort subroutine Message-ID: <109359@convex.convex.com> Date: 28 Nov 90 01:39:33 GMT References: <109155@convex.convex.com> <10521@jpl-devvax.JPL.NASA.GOV> Sender: usenet@convex.com Reply-To: tchrist@convex.COM (Tom Christiansen) Organization: CONVEX Software Development, Richardson, TX Lines: 39 In article <10521@jpl-devvax.JPL.NASA.GOV> lwall@jpl-devvax.JPL.NASA.GOV (Larry Wall) writes: >In article <109155@convex.convex.com> I wrote: >: wouldn't this be nice: >: >: @out = sort { $a <=> $b; } @in; >It would be possible, but apart from the problem you mentioned of making it >hard to find the list, I also think people should occasionally be encouraged >to name their abstractions. By all means. It's just that the quoted line above seems to be more readable than naming a subroutine for the sort; it would seem easier on both the writer and the reader of the code. I know in teaching perl, students have more than once asked me whether this was possible as soon as I show them how sort takes an optional subroutine. My response generally begins with "Alas, no; ...". >Of course, the fact that it would be hard to implement has nothing to >do with it... :-) I see we come at last to the meat of the matter. :-) In the meantime (and perhaps forever), you can always write a sort() function like this if you really want to: @out = &sort('$a <=> $b', @in); and a byreference version like this: @out = &sortr('$a <=> $b', *in); so that you don't try this: @out = &sortr('$a <=> $b', 3, 4, 2, 1, 4, 98); Naw, that's too complex. I'll go back to naming subroutines for a while. --tom