Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个数组,我想加入它的第 5 个和第 6 个条目!
喜欢:@array(1,2,3,4,5,6,7,8,9) 应该是 @array(1,2,3,4,56,7,8,9)
我怎么能做到这一点?我刚刚在互联网上找到了如何合并两个数组,但不是两个条目......
提前致谢。最好的问候,约翰。
最简单的方法是与数组切片splice一起使用。
splice
use warnings; use strict; my @array = (1,2,3,4,5,6,7,8,9); splice @array, 4, 2, join('', @array[4,5]); print "@array";
my @a = (1,2,3,4,5,6,7,8,9); my @b = (@a[0..3], join('',@a[4..5]), @a[6..8]); print "@b\n"; # <---- prints: 1 2 3 4 56 7 8 9