home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #19 / NN_1992_19.iso / spool / comp / lang / perl / 5551 < prev    next >
Encoding:
Internet Message Format  |  1992-08-27  |  1.4 KB

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