Last active
March 25, 2019 11:01
-
-
Save anonur/404033fa2dafabbde6ca752d300ecb91 to your computer and use it in GitHub Desktop.
Number comparison by sort() function
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#!/usr/bin/perl | |
#num_sort.plx | |
use warnings; | |
use strict; | |
my @unsorted = (1, 2, 11, 24, 3, 36, 40, 4); | |
my @string = sort { $a cmp $b } @unsorted; #with cmp, we compare $a and $b variables. | |
print "String sort: @string\n"; | |
my @number = sort { $a <=> $b } @unsorted; # <=> helps us to sorting numbers. | |
print "Numeric sort: @number\n"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment