微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Perl 读写 .gz .tgz 等压缩文件

1. 使用PERL直接读取压缩文件 use pipe

.gz格式文件

1
open(FIN,"gzip -dc $infilename|") or die ("can not open $infilename/n");

.tgz(.tar.gz)格式文件

ottom: 0px; padding-left: 5px; font-family: 'Courier New',"tar -xf $infilename -o|") or die ("can not open $infilename/n");

7zip格式文件

ottom: 0px; padding-left: 5px; font-family: 'Courier New',"7za e -so $infilename|") or die ("can not open $infilename/n");

这个可以直接用

2. 用PerlIO包
1)在*.pl前加上

1
2
use lib "/libPath"; 
use PerlIO::gzip;


2)在用的时候:

1
2
open FI, "<:gzip", "$fi"; 
open FO, ">:gzip", "$fo";

3. 用 File::Package;

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
#!/usr/bin/perl -w 
use strict; 
 
use File::Package; 
 
my $uut='Tie::Gzip'; 
my $fp='File::Package'; 
$fp->load_package($uut); 
 
tie *GZIP,'Tie::Gzip'; 
my $gzip=/*GZIP; 
open($gzip,"> test.gz"); 
 
while(my $line=<$gzip>){ 
chomp $line; 
print"$line/n"; 
} 
close $gzip; 
 
tie *OUT,'Tie::Gzip'; 
my $out=/*OUT; 
open($out,"> test.gz"); 
print $out "I want to kNow more!/n" 
close $out;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐