> -----Original Message-----
> From: Richard Adams [mailto:[EMAIL PROTECTED]]
> Sent: Monday, May 06, 2002 10:18 AM
> To: [EMAIL PROTECTED]
> Subject: Sorting problem
>
>
> Hello,
> I've got an array of arrays, and want to sort by the 3rd
> element of the
> subarray. I then want to print out the sorted array, showing
> the index and
> values. E.g.,
>
> @AoA = (
> [23.56, 65.2, 12.4],
> [13, 56, 87],
> [45,876, 23],
> etc
> )
>
>
> And then the printout should look like:
> 1: 87
> 2: 23
> 3: 12.4
>
> I've tried
> @sorted = {$a ->[2] <=> $b ->[2]} @AoA but this gives a "cannot
> modify.."error.
> I've a feeling this is really trivial but have got abit
> bogged down with
> it...
You forgot the word sort!
@sorted = sort {$a->[2] <=> $b->[2]} @AoA;
^^^^
Also, your example output indicates you probably want to
sort in descending order, which would be:
@sorted = sort {$b->[2] <=> $a->[2]} @AoA;
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]