Path: utzoo!utgpu!news-server.csri.toronto.edu!rutgers!usc!samsung!munnari.oz.au!comp.vuw.ac.nz!ajv From: Andrew.Vignaux@comp.vuw.ac.nz (Andrew Vignaux) Newsgroups: comp.lang.perl Subject: Re: sort Message-ID: <1990Aug22.111018.3329@comp.vuw.ac.nz> Date: 22 Aug 90 11:10:18 GMT References: <1990Aug21.202005.26275@uvaarpa.Virginia.EDU> <1990Aug21.224327.20194@iwarp.intel.com> Sender: news@comp.vuw.ac.nz (News Admin) Organization: Comp Sci, Victoria University, Wellington, New Zealand. Lines: 39 In article <1990Aug21.224327.20194@iwarp.intel.com>, merlyn@iwarp.intel.com (Randal Schwartz) writes: >sub by_the_numbers { > $a - $b; >} The original poster asked about sorting integers so this answer is right. However, there is a possible trap. I couldn't work out why @a = (50.1, 50.4, 50.2); @sorta = sort by_the_numbers @a; print "@sorta\n"; sometimes didn't work for me (well actually, imagine a LARGE list with a few |element1 - element2| < 0.5) "sort" wants integers (<, ==, >) 0 not reals! Is there a better/stronger/faster "float" comparison function than sub by_the_numbers { $a > $b ? 1 : $a < $b ? -1 : 0; } especially if $a and $b are indexes into an associative array? e.g ... $foo{$a} > $foo{$b} ? ... Here's an interesting sorter (extracted so my one-liner fits ;-) I think you can tell that perl is using qsort "as time goes by". $s=(localtime(time))[0]; sub n { ($a - $b) * $s; } print grep(s/.*\t//,sort n grep($_=++$i/-50."\t$_",split(/\n*/,<