[root@stationx perl]# cat rsort.pl    
#!/usr/bin/perl    
#sorting numbers with an unnamed subroutine    
@numbers=;    
chomp(@sorted_ns=sort{$a<=>$b}(@numbers));    
print "the sorted numbers are:@sorted_ns\n";    
 

perl自学小练习_第1张图片

[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";       
 

 

perl自学小练习_第2张图片