返回列表 回复 发帖

[转帖]perl特殊排序代码

有关数组的库函数
(1)sort--按字符顺序排序
   @array = ("this", "is", "a","test");
   @array2 = sort(@array); # @array2 = ("a","is", "test", "this")
   @array = (70, 100, 8);
   @array = sort(@array); # @array = (100, 70, 8 ) now
( 2)reverse--反转数组
   @array2 = reverse(@array);
   @array2 = reverse sort (@array);
(3)chop--数组去尾
   chop的意义是去掉STDIN(键盘)输入字符串时最后一个字符--换行符。而如果它作用到数组上,则将数组中每一个元素都做如此处理。
   @list = ("rabbit", "12345","quartz");
   chop (@list); # @list = ("rabbi", "1234","quart") now
( 4)join/split--连接/拆分
   join的第一个参数是连接所用的中间字符,其余则为待连接的字符数组。
   $string = join(" ", "this", "is","a", "string"); # 结果为"this is a string"
   @list = ("words","and");
   $string = join("::", @list, "colons"); #结果为"words::and::colons"
   @array = split(/::/,$string); # @array = ("words","and", "colons") now
哈哈哈!!!!你的IP是不是?我都知道了!!!
返回列表