home *** CD-ROM | disk | FTP | other *** search
- Newsgroups: comp.lang.perl
- 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
- From: Tom Christiansen <tchrist@convex.COM>
- Subject: Re: sorting problem
- Originator: tchrist@pixel.convex.com
- Sender: usenet@news.eng.convex.com (news access account)
- Message-ID: <1992Nov12.211431.6740@news.eng.convex.com>
- Date: Thu, 12 Nov 1992 21:14:31 GMT
- Reply-To: tchrist@convex.COM (Tom Christiansen)
- References: <BxM5w2.Iyr@immd4.informatik.uni-erlangen.de>
- Nntp-Posting-Host: pixel.convex.com
- Organization: Convex Computer Corporation, Colorado Springs, CO
- Keywords: sort
- X-Disclaimer: This message was written by a user at CONVEX Computer
- Corp. The opinions expressed are those of the user and
- not necessarily those of CONVEX.
- Lines: 30
-
- From the keyboard of mnrausch@cip.informatik.uni-erlangen.de (Martin Rausche):
- :I need a fast sorting routine for the following problem:
- :I have a database and the entries look like this:
- :keyword;author;title;owner
- :My solution:
- :
- :sub byname
- :{
- : @ah=split(/;/,$a);
- : @be=split(/;/,$b);
- : shift(@ah);
- : shift(@be);
- : $ah=join(";",@ah);
- : $be=join(";",@be);
- : $ah cmp $be;
- :}
- :
- :@data=sort byname @data;
- :
- :This is a very slow procedure, but how can I speed it up?
-
- for (@data) { push(@idx, /^[^;]*;(.*)/) }
- @data = @data[sort { $idx[$a] cmp $idx[$b] } 0..$#idx];
-
- --tom
- --
- Tom Christiansen tchrist@convex.com convex!tchrist
-
- #define NULL 0 /* silly thing is, we don't even use this */
- --Larry Wall in perl.c from the perl source code
-