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

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 (Prior)
on Nov 02, 2017 at 14:56 UTC ( #1202619=note: print w/replies, xml ) Need Help??


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 :)

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (5)
As of 2021-06-16 14:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    What does the "s" stand for in "perls"? (Whence perls)












    Results (76 votes). Check out past polls.

    Notices?