Next The Perl Hardware Store DC.pm Version 42

The Indirect Indirect Sort

     @fruit   = qw(Durian Cherry Apple Eggplant Banana);
     @indices = sort {$fruit[$a]   cmp $fruit[$b]  } (0 .. $#fruit);
     @ranks   = sort {$indices[$a] <=> $indices[$b]} (0 .. $#fruit);
        @ordinal = qw(first second third fourth fifth);
        for ($i=0; $i<@fruit; $i++) {
          print "The $fruit[$i] will come $ordinal[$ranks[$i]]\n";
        }
        # ``The Durian will come fourth.''
        # ``The Cherry will come third.''


Next Copyright © 2003 M. J. Dominus