- 论坛徽章:
- 0
|
请问各位大大..读取的文本文件是.Z的压缩包, 我尝试用read或者sysread来读,在匹配的时候均出现问题(如无法标准输出)!用while<>却没有问题,之前MMMIX说过 读取的文本文件是.Z的压缩包最好使用binmode, 请各位大大帮忙看一下是什么问题?
- sub creatTmp(){ #read each line and put the attribute to record hash
- my ($infile,$mmsgz,$smtingz,$iomgz)= @_;
- my $tmpStatus;
- my $tmpStatuscode;
- my $tmpStart;
- my $tmpEnd;
- my $buffer= "";
- if(!open(INFILE,"zcat $infile|")){
- die("Could not open file $infile:$!");
- }
- binmode(INFILE);
- while(<INFILE>){
- #while(sysread(INFILE,$buffer,1024)){
- #while(read(INFILE,$buffer,1024)){
- #process and count
- #next if $buffer=~/^Record.*\(.*\).*\"MiepPush.+\"/../End/;
- next if /^Record.*\(.*\).*\"MiepPush.+\"/../End/;
- #if ($buffer=~/(^Record.*\(\d+\).*\"MiepPull.+")/){
- if (/(^Record.*\(\d+\).*\"MiepPull.+")/){
- $tmpStart=$1;
- #} elsif ($buffer=~/\s+\"(.*)\"\s\=\s\"(.*)\"/){
- } elsif (/\s+\"(.*)\"\s\=\s\"(.*)\"/){
- $tmpStatus = $1;
- $tmpStatuscode = $2;
- $recordhash{$tmpStatus} = $tmpStatuscode;
- #} elsif ($buffer=~/(^End.*Record.*\(\d+\))/){
- } elsif (/(^End.*Record.*\(\d+\))/){
- $tmpEnd = $1; #在这里开始便无法输出数据
- if ($recordhash{"url"}=~/http\:\/\/mms\.smartone.+|202\.140\.96\.(?=92|208|46|97|227|47).+|10\.16\.96\.(?=76
- |79|93|94|187|188|180|137|167).+/i){
- print $tmpStart."\n" ;
- foreach (keys %recordhash){
- print "\"".$_."\" = \"".$recordhash{$_}."\"\n";
- }
-
- print $tmpEnd."\n" ;
- }
- undef %recordhash;
- }
- }
- close(INFILE);
- }
复制代码
binmode(INFILE);
while(<INFILE> {
#while(sysread(INFILE,$buffer,1024)){
#while(read(INFILE,$buffer,1024)){
$buffer是能正常输出的..能确定匹配是没有错的..想问一下为什么无法输出
[ 本帖最后由 hyoryeo 于 2009-7-9 14:44 编辑 ] |
|