perl 之reverse-sort

今天碰到了两个perl的排序函数 ,reverse & sort
例如:

@array = 1..10; #@array=1,2,3,4,5,6,7,8,9,10
print @array; # print out 1,2,3,4,5,6,7,8,9,10
@b = reverse(@array);
print @b; #print out 10,9,8…….1

@c = sort(@b);
print @c; # print out 1,10,2,3,4,5…..9 此排序顺序主要依照第一个字符,如1在2前面,1在10前面

Posted in perl |

perl 之子函数

一、定义
子程序即执行一个特殊任务的一段分离的代码,它可以使减少重复代码且使程序易读。PERL中,子程序可以出现在程序的任何地方。定义方法为:
sub subroutine{
statements;
}
二 调用
调用方法如下:
1、用&调用
&subname;

sub subname{

}
2、先定义后调用 ,可以省略&符号
sub subname{

}

subname;
3、前向引用 ,先定义子程序名,后面再定义子程序体
sub subname;

subname;

sub subname{
[...]

Posted in perl |

perl之数组

数组是perl里面一种非常有用的东西 ,比如我们可以采用以下的方式为 perl数组赋值.
 perl |  copy code |? @arr = (’hello’,'world’,'welcome come to perl word!’);
也可以使用一下的方式为数组赋值:
 perl |  copy code |? @b=(1..10); # @b 元素为 1到20。
  对于字母也一样哦 ,
 perl |  copy code |? @b=("a".."z");
 perl |  copy code |? @empty=(); [...]

Posted in perl |

Get Adobe Flash playerPlugin by wpburn.com wordpress themes