Last active
September 6, 2019 19:49
-
-
Save marked/53dc84e91109064cd2d17e42127837dc to your computer and use it in GitHub Desktop.
Sort by Length, then Alphabetical
This file contains 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 | |
use warnings; | |
use strict; | |
my @lines = <>; | |
@lines = sort { | |
if (length($a) == length($b)) { | |
$a cmp $b; | |
} else { | |
length($a) <=> length($b); | |
} | |
} @lines; | |
print @lines; | |
---------------------------------------------------------------------------------------------------------------------- | |
#!/usr/bin/perl | |
use warnings; | |
use strict; | |
my @lines = <>; | |
@lines = sort { | |
length($a) == length($b) ? $a cmp $b : length($a) <=> length($b); | |
} @lines; | |
print @lines; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment