On Sun, 2008-08-03 at 01:53 +0530, 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?
> 
> Thanks for you help in advance.
> 
> Regards.
> 
> -- 
> Gunwant Singh.
> 
> "What is the sound of Perl? 
> Is it not the sound of Wall that people bang their heads against?"
> 
> 

I'm not sure what you mean but I think this answers your question:

#!/usr/bin/perl

use strict;
use warnings;
use utf8;

use Data::Dumper;
$Data::Dumper::Sortkeys = 1;
$Data::Dumper::Indent   = 1;
$Data::Dumper::Maxdepth = 0;

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 @sort12 = map { $_->[0] }
             sort { $a->[1] <=> $b->[1] || $a->[2] <=> $b->[2] }
             map { [ $_, split( /:/, $_ ) ] } @list;

my @sort21 = map { $_->[0] }
             sort { $a->[2] <=> $b->[2] || $a->[1] <=> $b->[1] }
             map { [ $_, split( /:/, $_ ) ] } @list;

print Dumper [EMAIL PROTECTED], [EMAIL PROTECTED], [EMAIL PROTECTED];

__END__



-- 
Just my 0.00000002 million dollars worth,
  Shawn

"Where there's duct tape, there's hope."

"Perl is the duct tape of the Internet."
        Hassan Schroeder, Sun's first webmaster


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


Reply via email to