[root@stationx perl]# cat rsort.pl
#!/usr/bin/perl
#sorting numbers with an unnamed subroutine
@numbers=<STDIN>;
chomp(@sorted_ns=sort{$a<=>$b}(@numbers));
print "the sorted numbers are:@sorted_ns\n";
[root@stationx perl]# cat sort.pl
#!/usr/bin/perl
@str=(1,5,95,10,1000,a,B,z);
@str_sort=sort(@str);
print "@str_sort\n";
sub num1 { $a <=> $b; }
@number_sort=reverse(sort num1 -10,0,5,95,54,23,-10010,1000);
print "@number_sort.\n";
sub num2 { $a <=> $b; }
@number_sort=sort num2 -10,0,5,95,54,23,-10010,1000;
print "@number_sort.\n";
sub num3 { $b <=> $a; }
@number_sort=sort num3 -10,0,5,95,54,23,-10010,1000;
print "@number_sort.\n";
转载于:https://blog.51cto.com/perfect/868917