in reply to Indexing a data structure
Fish.
my @b = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $a[ $_ ]->{total}, $_ ] } 0..$#a;
Update: Frell, left off the subscript inside the sort block.
$a[0]->{total} = 0; $a[1]->{total} = 10; $a[2]->{total} = 50; $a[3]->{total} = 40; $a[4]->{total} = 30; $a[5]->{total} = 20; @b = map { $_->[1] } sort { $b->[0] <=> $a->[0] } map { [ $a[$_]->{total}, $_ ] } 1..$#a; print "$b[$_] = $a[$b[$_]]->{total}\n" for 0..$#b;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Indexing a data structure
by ChrisR (Hermit) on Oct 16, 2003 at 02:39 UTC | |
by graff (Chancellor) on Oct 16, 2003 at 03:11 UTC | |
by ChrisR (Hermit) on Oct 16, 2003 at 14:04 UTC | |
|
Re: Re: Indexing a data structure
by Roger (Parson) on Oct 16, 2003 at 06:22 UTC | |
by Fletch (Bishop) on Oct 17, 2003 at 00:49 UTC |