Clownburner has asked for the wisdom of the Perl Monks concerning the following question:
If I sort this beastie, it works fine like this:push(@alldata, { name => $filename, data => $data });
But I can't figure out how to sort two different arrays together, for example if I want the highest values from a combination of $opt{data} = 1 and $opt{data} = 2. I tried this:my @maxref = sort { $b->{data}->[$opt{data}] <=> $a->{data}->[$opt{dat +a}] } @alldata;
But that didn't work, and I'm wasting two sort functions, so obviously this is highly suboptimal code. I'm new to perl and although I've had some successes these multidimensional arrays are blowing my tiny mind. Any suggestions??my @maxtmp1 = sort { $b->{data}->[0] <=> $a->{data}->[0] } @alldata; my @maxtmp2 = sort { $b->{data}->[1] <=> $a->{data}->[1] } @alldata; @maxtemp = (@maxtmp1, @maxtmp2); @maxref = sort { $b->{data} <=> $a->{data} @maxtemp;
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Help with multidimensional sorting on arrays of hashed arrays
by arturo (Vicar) on Mar 10, 2001 at 01:03 UTC | |
by Clownburner (Monk) on Mar 10, 2001 at 01:15 UTC | |
by arturo (Vicar) on Mar 10, 2001 at 02:35 UTC | |
by Clownburner (Monk) on Mar 13, 2001 at 00:26 UTC | |
|
Re: Help with multidimensional sorting on arrays of hashed arrays
by Tuna (Friar) on Mar 10, 2001 at 01:06 UTC | |
by petral (Curate) on Mar 10, 2001 at 04:03 UTC |