On Jun 12, Martin van-Eerde said:

>What I need to do is sort the data in the second array in ascending 
>order and then print out with the corresponding elements from the 
>first array.
>
>It seems to work, apart from being in descending order, but my 
>main problem is perl complaining about a depreciated use of split @
>
>Thanks for any help!
>
>my @first = qw(high medium low apex);
>my @second = qw(100.00 50.50 34.25 23.99);

To sort parallel arrays, sort the INDICES of one of the arrays.

  my @idx = sort { $second[$a] <=> $second[$b] } 0 .. $#second;

  print "@first[@idx]\n";
  print "@second[@idx]\n";

>print sort {split( "~", $a) <=> split( "~", $b)} @result; 

You'd need to do:

  (split '~', $a)[0]

or

  (split '~', $a)[1]

depending on the field you wanted.  But the sort-the-index approach is far
better for this task.

-- 
Jeff "japhy" Pinyan      [EMAIL PROTECTED]      http://www.pobox.com/~japhy/
I am Marillion, the wielder of Ringril, known as Hesinaur, the Winter-Sun.
Are you a Monk?  http://www.perlmonks.com/     http://forums.perlguru.com/
Perl Programmer at RiskMetrics Group, Inc.     http://www.riskmetrics.com/
Acacia Fraternity, Rensselaer Chapter.         Brother #734
**      Manning Publications, Co, is publishing my Perl Regex book      **

Reply via email to