首页 > 代码库 > Perl实现新增内容统计

Perl实现新增内容统计

#! /usr/bin/perluse strict;use utf8;binmode(STDIN,":encoding(utf8)");binmode(STDERR,":encoding(utf8)");binmode(STDOUT,":encoding(utf8)");&extend("/home/hqh/桌面/2",1,",","/home/hqh/桌面/1",1,",","/home/hqh/桌面/result");sub extend{    my($infile1,$col1,$sep1,$infile2,$col2,$sep2,$outfile)=@_;
  #infile1和infile2为比较的两个文件,infile1第$col1列和infile2的第$col2列进行比较,输出到outfile中
open HD1,$infile1; binmode(HD1,"encoding(utf8)"); my @data1=<HD1>; close HD1; open HD2,$infile2; binmode(HD2,"encoding(utf8)"); my @data2=<HD2>; close HD2; open FD,">$outfile"; binmode(FD,":encoding(utf8)"); my %h; foreach(@data1){ chomp($_); my @temp=split($sep1,$_); $h{$temp[$col1]}=1 } foreach(@data2){ chomp($_); my @temp=split($sep2,$_); if(!exists($h{$temp[$col2]})){ print FD $temp[$col2],"\n"; } } close FD; }

 

Perl实现新增内容统计