perl数组的多数字下标示例代码
perl数组中正常的下标运算,想必大家都比较熟悉,这里不作说明。
本文想说的是perl数组下标的多数字取值,可以极大的方便数组的操作。
注意:这些数字是从0 到 $#array的。
子数组
代码如下:
@array = (1, 2, 3, 4, 5); @subarray = @array[0,1]; # @subarray = (1, 2) @subarray2 = @array[1..3]; # @subarray2 = (2,3,4) @array[0,1] = ("string", 46); # @array =("string",46,3,4,5) now @array[0..3] = (11, 22, 33, 44); # @array = (11,22,33,44,5) now @array[1,2,3] = @array[3,2,4]; # @array = (11,44,33,5,5) now @array[0..2] = @array[3,4]; # @array = (5,5,"",5,5) now
可以用子数组形式来交换元素:
代码如下:
@array[1,2] = @array[2,1];
相关推荐
边城客栈学无止境 2020-07-05
Walter的学习笔记 2020-07-04
A宇 2020-06-14
边城客栈学无止境 2020-06-10
邓博学习笔记 2020-06-03
davidliu00 2020-05-26
ShiShuo 2020-05-16
Aggressivesnail 2020-05-10
ShiShuo 2020-04-26
hanxingwang00 2020-04-22
davidliu00 2020-03-06
ShiShuo 2020-03-06
ShiShuo 2020-03-05
Aggressivesnail 2020-02-28
aaLiweipeng 2020-02-01
amberom 2020-01-16
Walter的学习笔记 2020-01-06