perl sort <=> and cmp
$ cat sort_chara.pl #!/usr/bin/perluse strict;
use warnings;
my @input = (
"Hello World!",
"You is all I need.",
"To be or not to be",
"There's more than one way to do it.",
"Absolutely Fabulous",
"Ci vis pacem, para belum",
"Give me liberty or give me death.",
"Linux - Because software problems should not cost money",
);
# Do a case-insensitive sort
my @sorted = sort { lc($a) cmp lc($b); } @input;
print join("\n", @sorted), "\n";
$ ./sort_chara.pl
Absolutely Fabulous
Ci vis pacem, para belum
Give me liberty or give me death.
Hello World!
Linux - Because software problems should not cost money
There's more than one way to do it.
To be or not to be
You is all I need.
页:
[1]