CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Advanced: Re: [ravikim] how do i sort in a descending order using perl Sort::External Module: Edit Log



1arryb
User

Dec 18, 2009, 9:41 AM


Views: 2572
Re: [ravikim] how do i sort in a descending order using perl Sort::External Module

Hi ravi,

Caveat: I haven't used Sort::External. Nevertheless, it seems most straightforward just to define the descending sort in a sortsub.

Code
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)


Edit Log:
Post edited by 1arryb (User) on Dec 18, 2009, 9:42 AM


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives