perl FileHandle 模块使用

打开多个文件时必备啊

 1 use FileHandle;
 2 
 3 my (%index,%fh);
 4 # 创建句柄,这里利用gzip 压缩下
 5 foreach my $k(keys %index){
 6     $fh{$k}=FileHandle->new("| gzip -c > ${k}_1.txt.gz");
 7 }
 8 
 9 # 输出内容到句柄绑定的文件
10 if(exists $fh{$key}){  
11     $fh{$key} -> print($out1);
12 }
13 
14 # 句柄关闭
15 foreach my $tmp(keys %fh){
16     $fh{$tmp} -> close;
17 }
本文版权归作者和博客园共有,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利.
原文地址:https://www.cnblogs.com/mmtinfo/p/14694483.html