Maxmelbin Neson (RBIN/EDM3) wrote:
> Hi,
>
> I have an array with following type of content
>
> ABC,Project1,file1.c,0.7,location1
> ABC,Project1,file1.c,0.25,location1
> ABC,Project1,file1.c,0.2,location1
> ABC,Project1,file2.c,0.6,location2
> CDE,Project1,atest1.txt,1.0,location3
> ABC,Project1,file1.c,3.2,location1
> ABC,Project1,file2.c,0.2,location2
> ABC,Project1,file1.c,0.1,location1
>
> The items marked in red in each line is the version number of all
> respective files ..
>
> Now I need to sort it first by Project/file name ie
> (ABC,Project1,file1.c) and then by their versions . So I can have an
> output like this
>
> ABC,Project1,file1.c,0.1,location1
> ABC,Project1,file1.c,0.2,location1
> ABC,Project1,file1.c,0.25,location1
> ABC,Project1,file1.c,0.7,location1
> ABC,Project1,file1.c,3.2,location1
> ABC,Project1,file2.c,0.2,location2
> ABC,Project1,file2.c,0.6,location2
> CDE,Project1,atest1.txt,1.0,location3
>
> The sort function will sort it as a string , but how do I sort each file
> name by their versions ..
If you had looked in perlfunc man page under sort (or used perldoc), you
would have found a Schwartzian transform.
use strict;
my @array = (
'ABC,Project1,file1.c,0.7,location1',
'ABC,Project1,file1.c,0.25,location1',
'ABC,Project1,file1.c,0.2,location1',
'ABC,Project1,file2.c,0.6,location2',
'CDE,Project1,atest1.txt,1.0,location3',
'ABC,Project1,file1.c,3.2,location1',
'ABC,Project1,file2.c,0.2,location2',
'ABC,Project1,file1.c,0.1,location1',
);
my @newarray = map { $_->[0] }
sort { $a->[3] cmp $b->[3] || $a->[4] <=> $b->[4]
} map { [$_, split /\s*,\s*/] } @array;
print "$_\n" foreach @newarray;
__END__
--
,-/- __ _ _ $Bill Luebkert Mailto:[EMAIL PROTECTED]
(_/ / ) // // DBE Collectibles Mailto:[EMAIL PROTECTED]
/ ) /--< o // // Castle of Medieval Myth & Magic http://www.todbe.com/
-/-' /___/_<_</_</_ http://dbecoll.tripod.com/ (My Perl/Lakers stuff)
_______________________________________________
Perl-Win32-Users mailing list
[email protected]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs