in reply to Re: Sorting Arrays
in thread Sorting Arrays

thank you very much. But why does this work??

Replies are listed 'Best First'.
Re: Re: Re: Sorting Arrays
by jlf (Scribe) on Jan 08, 2002 at 22:05 UTC
    my @indicies = sort { $a[$a] <=> $a[$b] } 0..$#a;

    merlyn is sorting a list of integers (0..$#a) corresponding to the indices of the elements of your array @a. Recall that within sort code blocks, $a and $b are special variables representing the two variables to be ordered each time the block is evaluated. So here,  $a[$a] <=> $a[$b] means sort the indices of the array by the contents of its elements.

    It's a bit confusing in this case because of the use of @a as your array variable and the use of $a and $b as special variables to sort.

    HTH,

    Josh
Re: Re: Re: Sorting Arrays
by merlyn (Sage) on Jan 08, 2002 at 21:54 UTC