perl自学小练习

前端之家收集整理的这篇文章主要介绍了perl自学小练习前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

[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,54,23,-10010,1000);       
print "@number_sort.\n";       

sub num2 { $a <=> $b; }       
@number_sort=sort num2 -10,1000;       
print "@number_sort.\n";       


sub num3 { $b <=> $a; }       
@number_sort=sort num3 -10,1000;       
print "@number_sort.\n";       
 

 

猜你在找的Perl相关文章