#!/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";
In reply to Re: How do i sort an numeric array without using sort function. Is ther any way to sort it just with loop in perl??
by tybalt89
in thread 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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |