perl文件读取之心得
2005-06-08 11:35
417 查看
在perl中用到的读文件一般有两种方法:
1.先把整个文件download到一个数组里面然后对数组进行遍历操作。
如:
open (IN,"alignresult.txt") ||(die "can not open the file input.txt/n$!");
my @all = <IN>;
foreach $line(@all){
process $line;}
或者
foreach $line(<IN>){...}
语义: 将文件load到数组中,在对数组进行遍历操作
这样子做得缺点是文件很大时,会占据很大内存,当然速度上占优。
2.为节省内存,一般建议如下操作
open (IN,"alignresult.txt") ||(die "can not open the file input.txt/n$!");
while ($line = <IN>){..}
这样的语义:
每次$line = <IN>,文件指针后移
1.先把整个文件download到一个数组里面然后对数组进行遍历操作。
如:
open (IN,"alignresult.txt") ||(die "can not open the file input.txt/n$!");
my @all = <IN>;
foreach $line(@all){
process $line;}
或者
foreach $line(<IN>){...}
语义: 将文件load到数组中,在对数组进行遍历操作
这样子做得缺点是文件很大时,会占据很大内存,当然速度上占优。
2.为节省内存,一般建议如下操作
open (IN,"alignresult.txt") ||(die "can not open the file input.txt/n$!");
while ($line = <IN>){..}
这样的语义:
每次$line = <IN>,文件指针后移
相关文章推荐
- perl文件读取之心得
- Perl文件读取经典用法----【转】
- perl 读取json 格式的文件
- perl读取文件
- perl从文件中读取数据并输出的实现代码
- [经验总结]解决Perl读取utf-8编码文件的问题
- perl 读取文件
- Perl随机读取文件行的方法
- Perl从文件中读取字符串的两种实现方法
- perl,读取所需文件的路径,然后打开相应的文件,并对文件中的DNA序列进行计数,substr函数对长字符串的片段化处理功能
- perl中同时读取两个文件并进行对应计算
- 利用 perl 调用 Java 类,通过读取文件 获取调用类返回值
- 分享:Perl打开与读取文件的方法
- java编程心得(十)——递归读取目录下的文件和子目录
- 疑问:Perl读取UTF8编码的文件,显示乱码。
- python学习心得(1) --- 大型文件的读取
- Perl 读取文件并进行split
- Perl中文件读取操作
- 今日学习心得之读取资源文件
- Perl读取Excel文件并解决中文乱码问题