Gunwant Singh wrote:
> Hi all,
> 
> I really appreciate all you guys there for the help you've provided to 
> me in the past.
> So here I am again with a Question.
> 
> I have a file with the following entries:
> 
> 1:17
> 4:3
> 4:11
> 4:13
> 11:16
> 12:10
> 13:2
> 19:5
> 20:7
> 26:12
> 28:4
> 33:15
> 33:17
> 35:9
> 36:1
> 42:14
> 43:6
> 44:8
> 46:0.. and so on
> 
> You will see that the left column is sorted. However the right one isn't.
> What I want to do is to sort the right one but the corresponding values 
> should remain the same.
> Notice the repeated values too.
> Any thoughts?

I think you mean you want to sort by the second field instead of the first one?
The code below should suit your purpose.

HTH,

Rob



use strict;
use warnings;

my @list = qw(
  1:17
  4:3
  4:11
  4:13
  11:16
  12:10
  13:2
  19:5
  20:7
  26:12
  28:4
  33:15
  33:17
  35:9
  36:1
  42:14
  43:6
  44:8
  46:0
);

my @sorted = sort {
  my @a = split /:/, $a;
  my @b = split /:/, $b;
  $a[1] <=> $b[1];
} @list;

print "$_\n" foreach @sorted;

-- 
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]
http://learn.perl.org/


Reply via email to