#!/usr/bin/perl # http://perlmonks.org/?node_id=1202584 use strict; use warnings; use Data::Dumper; my @unsorted = map {int (1000 * rand ())} (1..100); my @sorted = sort_try (@unsorted); sub sort_try { my @counts; push @{ $counts[$_] }, $_ for @_; map $_ ? @$_ : (), @counts; } print Dumper \ @sorted; # validity check print "@sorted" eq "@{[sort {$a<=>$b} @unsorted]}" ? "is sorted\n" : "is not sorted\n";
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: How do i sort an numeric array without using sort function. Is ther any way to sort it just with loop in perl??
by Tabish (Acolyte) on Nov 03, 2017 at 07:26 UTC | |
by choroba (Cardinal) on Nov 03, 2017 at 09:08 UTC | |
by Tabish (Acolyte) on Nov 03, 2017 at 09:18 UTC |