Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Wanet Telecoms Ltd on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

About ordering data

Status
Not open for further replies.

Alfio75

Programmer
Oct 25, 2005
25
MX
Hello guys. Does anybody know how to order ascendent a list of data?
What i mean is that i got 3 columns of data. What i need is to order them with respect to the first one, but i need all the 2 next colums get order at the same time that one.

Example

1 5 4
4 8 9
10 15 4
1 5 8
2 7 9

so after the ordering i wanna get those in the next way:

1 5 4
1 5 8
2 7 9
4 8 9
10 15 4
^
|
|
column that was ordered.
 
i got all those data in a file, so i think i could read those and order them.
 
assuming it's a text file with spaces between the numbers, a Schwartzian transform will do:

Code:
open(FH,'<file.txt') or die "$!";
my @sorted = map {$_->[0]}
             sort {$a->[1] <=> $b->[1] ||
                   $a->[2] <=> $b->[2] ||
                   $a->[3] <=> $b->[3]
             } map {chomp; [$_,split/\s+/]} <DATA>;
close(FH);
print map {"$_\n"} @sorted;
 
I see a typo in my code, this:

<DATA>

needs to be changed to:

<FH>
 
That's a nice code Kevin... This is working. The next step is to get it counting for n times it is getting the same X Y Z colums.

example
1 2 3
4 5 6
1 2 3
8 9 10
5 4 3

I wanna get this:
1 2 3
1 2 3
4 5 6
5 4 3
8 9 10

and:
1 2 3 is 2 times found
4 5 6 is 1 time
5 4 3 is 1 time
8 9 10 is 1 time

Thanks in advance
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top