Re: URGENT HELP WITH PERL CODE, PLEASE !!!!
| From: | Robin Vickery | Date: | Thu, 10 Aug 2000 10:34:28 +0000 |
| Subject: | Re: URGENT HELP WITH PERL CODE, PLEASE !!!! | ||
| References: | 1 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-11114@lists.php.net to get a copy of this message | ||
brucex.r.christensen@intel.com ("Christensen, BruceX R") writes:
> You can also do this this way (a direct translation of the Perl code, using
> a custom sort):
>
> $categAlpha = range(0,count($categName)-1);
> usort($categAlpha, custom);
> function custom($a,$b) {
> global $categName;
> if ($categName[$a] == $categName[$b]) {
> return 0;
> } elseif ($categName[$a] > $categName[$b]) {
> return 1;
> } else {
> return -1;
> }
> }
>
> Perl's much shorter :).
function custom($a,$b) {
global $categName;
$c = $categName;
return $c[$a]<$c[$b]?-1:$c[$a]!=$c[$b];
}
Still not as concise as Perl though :-(
--
Robin Vickery...............................................
Planet-Three, 3A West Point, Warple Way, London, W3 0RG, UK
Email: robin@planet-three.net Phone: +44 (0)794 670 6395