Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses
 
PerlMonks  

Re: Sorting Arrays Without using SORT function

by ikegami (Patriarch)
on Feb 15, 2011 at 18:53 UTC ( [id://888352]=note: print w/replies, xml ) Need Help??


in reply to Sorting Arrays Without using SORT function

Two solutions:

use Algorithm::Loops qw( NextPermute ); sub mysort { my @a = @_; 1 while NextPermute(@a); return @a; } my @unsorted = qw( a c b d ); my @sorted = mysort(@unsorted); print("@sorted\n");
use IPC::Run3 qw( run3 ); sub mysort { my @unsorted = map "$_\n", @_; run3([ 'sort' ], [ map "$_\n", @unsorted ], \my @sorted); chomp(@sorted); return @sorted; } my @unsorted = qw( a c b d ); my @sorted = mysort(@unsorted); print("@sorted\n");

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://888352]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others examining the Monastery: (5)
As of 2024-04-19 00:53 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found