读 《C程序员精通Perl》http://book.douban.com/subject/1232075/ 3.5节 笔记
#!/usr/bin/perl
use strict;
use warnings;
my @array = ();
while (1) {
print "input a number or <enter> to finish: ";
my $a=<STDIN>;
chomp ($a);
if ($a eq "") {
last;
}
print "input $a\n";
push(@array, $a);
}
print "\narray=@array\n";
my @sorted_array = sort @array;
printf "\nsorted_array = @sorted_array\n";
运行结果:
[root@localhost perl_practice]# ./sort.pl
input a number or <enter> to finish: z
input z
input a number or <enter> to finish: b
input b
input a number or <enter> to finish: a
input a
input a number or <enter> to finish: d
input d
input a number or <enter> to finish: t
input t
input a number or <enter> to finish:
array=z b a d t
sorted_array = a b d t z
[root@localhost perl_practice]#