in reply to Simple sorting by another parallel array

When I first looked at this I was annoyed that you didn't show a fancy trick for making a @sortedages too.

Then the cola kicked in and started kicking my self over and over. =) @sortedages = sort @ages;

*thump* *thump* *thump*

--
$you = new YOU;
honk() if $you->love(perl)

Replies are listed 'Best First'.
RE: RE: Simple sorting by another parallel array
by tye (Sage) on Sep 24, 2000 at 10:20 UTC

    You mean this?

    my @sorted_names= @names[ my @idx= sort {$ages[$a]<=>$ages[$b]} 0..$#ages ]; my @sorted_ages= @ages[@idx];

    This is much more efficient than sorting by age all over again.

    Update: Fixed my typo.

            - tye (but my friends call me "Tye")

      Nice! Cept you typo'd "args" should be "ages". Very nice tho. That is a fine use of array slicing...

      /me sticks idea into toolbox for later =)

      --
      $you = new YOU;
      honk() if $you->love(perl)