home *** CD-ROM | disk | FTP | other *** search
- Path: sparky!uunet!know!mips2!news.bbn.com!noc.near.net!nic.umass.edu!caen!zaphod.mps.ohio-state.edu!darwin.sura.net!sgiblab!sgigate!sgi!wdl1!wdl39!mab
- From: mab@wdl39.wdl.loral.com (Mark A Biggar)
- Newsgroups: comp.lang.perl
- Subject: Re: sorting problem
- Keywords: sort
- Message-ID: <1992Nov12.224027.3713@wdl.loral.com>
- Date: 12 Nov 92 22:40:27 GMT
- References: <BxM5w2.Iyr@immd4.informatik.uni-erlangen.de>
- Sender: news@wdl.loral.com
- Organization: Loral Western Development Labs
- Lines: 33
-
- In article <BxM5w2.Iyr@immd4.informatik.uni-erlangen.de> mnrausch@cip.informatik.uni-erlangen.de (Martin Rausche) writes:
- >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;
-
- split take a third parameter that specifies how many item to slipt into.
- This can be used to avoid the joins and shifts like so:
-
- sub byname {
- @ah=split(/;/,$a,2);
- @be=split(/;/,$b,2);
- $ah[1] cmp $be[1];
- }
-
- The splits also get speed up because they can quit as soon as the first ';'
- is seen.
-
- --
- Perl's Maternal Uncle
- Mark Biggar
- mab@wdl1.wdl.loral.com
-