home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / comp / lang / perl / 6965 < prev    next >
Encoding:
Text File  |  1992-11-12  |  1.7 KB  |  49 lines

  1. Newsgroups: comp.lang.perl
  2. Path: sparky!uunet!ferkel.ucsb.edu!taco!rock!stanford.edu!ames!sun-barr!cs.utexas.edu!zaphod.mps.ohio-state.edu!sol.ctr.columbia.edu!eff!news.oc.com!convex!tchrist
  3. From: Tom Christiansen <tchrist@convex.COM>
  4. Subject: Re: sorting problem
  5. Originator: tchrist@pixel.convex.com
  6. Sender: usenet@news.eng.convex.com (news access account)
  7. Message-ID: <1992Nov12.211431.6740@news.eng.convex.com>
  8. Date: Thu, 12 Nov 1992 21:14:31 GMT
  9. Reply-To: tchrist@convex.COM (Tom Christiansen)
  10. References: <BxM5w2.Iyr@immd4.informatik.uni-erlangen.de>
  11. Nntp-Posting-Host: pixel.convex.com
  12. Organization: Convex Computer Corporation, Colorado Springs, CO
  13. Keywords: sort
  14. X-Disclaimer: This message was written by a user at CONVEX Computer
  15.               Corp. The opinions expressed are those of the user and
  16.               not necessarily those of CONVEX.
  17. Lines: 30
  18.  
  19. From the keyboard of mnrausch@cip.informatik.uni-erlangen.de (Martin Rausche):
  20. :I need a fast sorting routine for the following problem:
  21. :I have a database and the entries look like this:
  22. :keyword;author;title;owner
  23. :My solution:
  24. :
  25. :sub byname
  26. :{
  27. :        @ah=split(/;/,$a);
  28. :        @be=split(/;/,$b);
  29. :        shift(@ah);
  30. :        shift(@be);
  31. :        $ah=join(";",@ah);
  32. :        $be=join(";",@be);
  33. :        $ah cmp $be;
  34. :}
  35. :
  36. :@data=sort byname @data;
  37. :
  38. :This is a very slow procedure, but how can I speed it up?
  39.  
  40.     for (@data) { push(@idx, /^[^;]*;(.*)/) } 
  41.     @data = @data[sort { $idx[$a] cmp $idx[$b] } 0..$#idx];
  42.  
  43. --tom
  44. -- 
  45.     Tom Christiansen      tchrist@convex.com      convex!tchrist
  46.  
  47.     #define NULL 0           /* silly thing is, we don't even use this */
  48.         --Larry Wall in perl.c from the perl source code
  49.