
1arryb
User
Dec 18, 2009, 9:41 AM
Post #2 of 2
(2066 views)
|
|
Re: [ravikim] how do i sort in a descending order using perl Sort::External Module
[In reply to]
|
Can't Post
|
|
Hi ravi, Caveat: I haven't used Sort::External. Nevertheless, it seems most straightforward just to define the descending sort in a sortsub.
use Sort::External; $output = '1.txt'; # You probably meant "input" here. open(FILE, $output); my $sortdesc = sub { $Sort::External::b <=> $Sort::External::a }; # Use cmp if your data are strings. my $sortex = Sort::External->new( sortsub => $sortdesc, mem_threshold => 1024**2 * 1024 ); while (<FILE>) { $sortex->feed($_); # tried to change it to ~$_ but did not work !!!!! } use Fcntl; $sortex->finish ( outfile => 'desc_Sorted_04323697_pbragg02@sprintpcs.com_.txt', flags => ( O_CREAT | O_WRONLY ), ); close(FILE The encode, sort, decode technique explicated in the Sort::External::Cookbook made my head hurt, but I don't think you're following it. Check out http://search.cpan.org/~creamyg/Sort-External-0.18/lib/Sort/External/Cookbook.pod#Descending_sort_order_using_the_%22bitwise_not%22_operator. Cheers, Larry
(This post was edited by 1arryb on Dec 18, 2009, 9:42 AM)
|