Skip to content

Instantly share code, notes, and snippets.

@marked
Last active September 6, 2019 19:49
Show Gist options
  • Save marked/53dc84e91109064cd2d17e42127837dc to your computer and use it in GitHub Desktop.
Save marked/53dc84e91109064cd2d17e42127837dc to your computer and use it in GitHub Desktop.
Sort by Length, then Alphabetical
#!/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