Hi ,

use Sort::External;
$output = '1.txt';    
open(FILE, $output);
my $sortex = Sort::External->new( mem_threshold => 1024**2 * 1024 );
while (<FILE>) 
{
   $sortex->feed($_);  # tried to change it to ~$_ but did not work !!!!!
}
use Fcntl;
$sortex->finish(
        outfile => 'desc_1.txt', # comes in ascending order !!
        flags => ( O_CREAT | O_WRONLY ),
);
close(FILE);

with the above code the file is getting sorted in ascending order. how do i sort in descending order ?

thanks in advance,
ravikim

new() :

my $sortscheme = sub { $Sort::External::b <=> $Sort::External::a };

    my $sortex = Sort::External->new(
        mem_threshold   => 1024**2 * 16,     # default: 1024**2 * 8 (8 MiB)
        cache_size      => 100_000,          # default: undef (disabled) 
        sortsub         => $sortscheme,      # default sort: standard lexical
        working_dir     => $temp_directory,  # default: see below
    );

Construct a Sort::External object.
...
..
sortsub -- A sorting subroutine. Be advised that you MUST use $Sort::External::a and $Sort::External::b instead of $a and $b in your sub.

There are only about 300 examples in the docs on how to sort in descending order. Because you seem incapable of copying one of those, I suggest you first post some code that sorts an array of 3 numbers in descending order using perl's built in sort() function. Then compare your example to the one above to see what changes you need to make.

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.