lrx182125 发表于 2018-9-1 06:40:05

perl sort <=> and cmp

$ cat sort_chara.pl  #!/usr/bin/perl
  use 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]
查看完整版本: perl sort <=> and cmp