perl大文件读取处理的模块介绍
时间:2023-12-27 20:10:27
该模块用perl的数组代表一个文件,文件的每一行对应数组的一个元素,第一行为元素0,第二回为1,...
文件本身实际并不加载到内存,对数组元素的操作立刻作用到文件里。最大的方便是可以任意指定处理开头结尾的某几行。
基本用法:
use Tie::File;
tie @array, 'Tie::File', filename or die ...;
$array[13] = 'blah'; # line 13 of the file is now 'blah'
print $array[42]; # display line 42 of the file
$n_recs = @array; # how many records are in the file?
$#array -= 2; # chop two records off the end
for (@array) {
s/PERL/Perl/g; # Replace PERL with Perl everywhere in the file
}
# These are just like regular push, pop, unshift, shift, and splice
# Except that they modify the file in the way you would expect
push @array, new recs...;
my $r1 = pop @array;
unshift @array, new recs...;
my $r2 = shift @array;
@old_recs = splice @array, 3, 7, new recs...;
untie @array; # all finished
更多功能请大家参考cpan上的文档。
标签:大文件读取
![](/images/zang.png)
![](/images/jiucuo.png)
猜你喜欢
Access报错:文件共享锁定数溢出
2009-03-21 18:32:00
深入理解Python中的 __new__ 和 __init__及区别介绍
2022-11-15 12:23:36
Python中eval带来的潜在风险代码分析
2023-05-24 03:29:03
Ajax:拥抱JSON,让XML走开
2007-10-12 20:01:00
Go 多环境下配置管理方案(多种方案)
2024-05-25 15:15:37
![](https://img.aspxhome.com/file/2023/8/123948_0s.png)
使用Python实现毫秒级抢单功能
2022-10-17 18:46:16
![](https://img.aspxhome.com/file/2023/3/109583_0s.png)
MySQL 查询某个字段不重复的所有记录
2024-01-25 09:22:58
python实现得到一个给定类的虚函数
2022-03-27 19:31:11
Python遗传算法Geatpy工具箱使用介绍
2021-11-02 02:21:16
![](https://img.aspxhome.com/file/2023/8/105598_0s.png)
Mysql数据库存储过程基本语法讲解
2024-01-20 04:46:35
Python3中的真除和Floor除法用法分析
2023-10-11 09:01:45
Python参数解析模块sys、getopt、argparse使用与对比分析
2021-12-19 17:39:58
![](https://img.aspxhome.com/file/2023/1/80781_0s.png)
简单谈谈mysql左连接内连接
2024-01-13 06:54:24
pandas 数据归一化以及行删除例程的方法
2022-05-23 09:11:23
oracle 服务启动,关闭脚本(windows系统下)
2024-01-21 08:49:18
PDO::exec讲解
2023-06-13 04:04:40
深入理解Golang的单元测试和性能测试
2024-05-05 09:27:42
python 解决flask 图片在线浏览或者直接下载的问题
2022-05-15 06:24:57
python数据可视化之matplotlib.pyplot基础以及折线图
2023-03-04 22:10:01
![](https://img.aspxhome.com/file/2023/3/101093_0s.png)
MySQL查询不含周末的五天前的日期
2008-11-11 12:28:00