in reply to How do i sort an numeric array without using sort function. Is ther any way to sort it just with loop in perl??

#!/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";
  • Comment on Re: How do i sort an numeric array without using sort function. Is ther any way to sort it just with loop in perl??
  • Download Code

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

    thanks, its nice!

    What does @s_ mean?

      @$_ is a shorter way of saying @{ $_ } or $_->@*, it dereferences $_ as an array reference, i.e. it returns the referenced array.
      my $array_ref = [ 11, 12, 42 ]; my @array = @$array_ref; # Same as @array = (11, 12, 42).

      ($q=q:Sq=~/;[c](.)(.)/;chr(-||-|5+lengthSq)`"S|oS2"`map{chr |+ord }map{substrSq`S_+|`|}3E|-|`7**2-3:)=~y+S|`+$1,++print+eval$q,q,a,

        Thank you very much! the Example was good and clear :)