Perl的那些技巧:平均切割数组
2013-11-30 11:42
375 查看
有些时候需要将数组分成长度相同的多个子数组,比如批量查询数据库。
这时,我们可以用splice完成这个功能。代码如下:
这时,我们可以用splice完成这个功能。代码如下:
#!/usr/bin/env perl use strict; use warnings; my @chunks; my $size = 10; my @array = (1..100); push @chunks, [splice(@array, 0, $size)] while @array; foreach my $ref (@chunks) { print join("\t", @$ref)."\n"; }
相关文章推荐
- Perl的那些技巧:为数组元素加双引号
- 7个perl数组高级操作技巧分享
- Perl的那些技巧:使用strict、warnings发现问题
- perl-切割数组
- 7个perl数组高级操作技巧分享
- Perl技巧 两个数组的取交集,并集与补集
- HDOJ 题目4970 Killing Monsters(技巧,数组)
- Codeforces edu 8 E. Zbazi in Zeydabad 树状数组 处理技巧
- c语言模拟perl python中的数组负数索引
- IOS_技巧分享之另类随机数组
- (经典的异或技巧)数组中只出现一次的数字 (两种方法)
- linux shell 数组建立及使用技巧
- perl 传递数组作为参数
- 技巧-字符串sting>转>数组array
- [Java技巧] 如何复制数组的一部分到另外一个数组?
- JavaScript数组常用操作技巧汇总
- PHP数组操作汇总 php数组的使用技巧
- 10个必须掌握的PHP关联数组使用技巧
- m个人的成绩放在score数组中,利用fun函数返回低于平均分得人数,降低于平均分得人成绩放在below中
- C语言结构数组 动态录入游戏英雄信息并且计算平均生命值