加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 大数据 > 正文

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

发布时间:2020-12-15 20:50:18 所属栏目:大数据 来源:网络整理
导读:1. 使用PERL直接读取压缩文件 use pipe .gz格式文件 1 open ( FIN , "gzip -dc $infilename|" ) or die ( "can not open $infilename /n " ) ; .tgz(.tar.gz)格式文件 "tar -xf $infilename -o|" ) or die ( "can not open $infilename /n " ) ; 7zip格式文

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

.gz格式文件

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

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

"tar -xf $infilename -o|") or die ("can not open $infilename/n");

7zip格式文件

"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;

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读