Suppose @names is a list of names, and @ages is their respective ages. You want the names sorted by ages, and you don't want to get into references.
@sorted_names = @names[sort { $ages[$a] <=> $ages[$b] } 0..$#ages];

Replies are listed 'Best First'.
RE: Simple sorting by another parallel array
by extremely (Priest) on Sep 24, 2000 at 02:15 UTC

    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)

      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)