home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!ogicse!reed!romulus!merlyn
- From: merlyn@romulus.reed.edu (Randal L. Schwartz)
- Newsgroups: comp.lang.perl
- Subject: Re: Ordering indices based on their values
- Message-ID: <MERLYN.92Aug27102846@romulus.reed.edu>
- Date: 27 Aug 92 17:28:51 GMT
- Article-I.D.: romulus.MERLYN.92Aug27102846
- References: <GLENN.92Aug26122420@capella.clsi.COM> <1992Aug27.151949.10917@genrad.com>
- Sender: news@reed.edu (USENET News System)
- Distribution: comp.lang.perl
- Organization: Reed College
- Lines: 25
- In-Reply-To: jpn@genrad.com's message of 27 Aug 92 15:19:49 GMT
-
- In article <1992Aug27.151949.10917@genrad.com> jpn@genrad.com (John P. Nelson) writes:
-
- #!/usr/local/perl
-
- # makeindex subroutine builds and returns a sorted index array.
- # argument is a numeric array passed by reference. To create
- # an index for a string array, use "cmp" instead of "<=>"
- sub makeindex {
- local(*arr) = @_;
- local(@i) = (0 .. $#arr);
-
- sort { $arr[$b] <=> $arr[$a] } @i;
- }
-
- The @i array is unnecessary. Just do:
-
- sort { $arr[$b] <=> $arr[$a] } $[ .. $#arr;
-
- (Use $[ for less "Surprise!" factor)
-
- print +(split(//,",rekcah lreP rehtona tsuJ"))[sort {$b<=>$a} 0..24]
- --
- Randal L. Schwartz / Stonehenge Consulting Services (503)777-0095
- merlyn@reed.edu (guest account) merlyn@ora.com (better for permanent record)
- cute quote: "Welcome to Portland, Oregon -- home of the California Raisins!"
-