正文

perl实现的两个文件对比并对数据进行筛选的脚本代码(perl字符串)没想到

文章摘要

这篇文章介绍了如何使用 Perl 编程语言处理两个文本文件,分别是 f:perlf.txt 和 f:perla.csv。文章详细描述了如何通过 Perl 读取并处理文件内容,包括使用 while 循环遍历文件内容,使用 split 和 chomp 函数处理数据,使用正则表达式匹配特定 URL 格式,并将符合条件的数据存储到变量中。文章进一步解释了如何将处理后的数据输出到 a.csv 文件,并展示了完整的代码实现。总体而言,文章突出了 Perl 在文件处理和数据匹配中的应用。

#!/usr/bin/perl

my %scyjm; 

open (CONTACT,”f:\\perl\\f.txt”)||die(“can not open the file!”);  

while () 

{ 

  next if /^#/;#if($_=~/^#/的简写 

  chomp; 

  my @information=split;# my @information=split/\s+/,$_;的简写 

  next if(($information[1]=~/\https://www.jb51.net/article/) && ($information[2]=~/\https://www.jb51.net/article/)); 

  $scyjm{$information[13]}->{$information[0]}=$information[3]; 

} 

close CONTACT; 

open (SC,”f:\\perl\\a.csv”)||die(“can not open the file!”); 

while() 

{ 

   chomp; 

   my @sc=split; 

   if ( $scyjm{$sc[1]}{$sc[2]}) 

   { 

      print “$sc[0] $sc[1] $sc[2] $sc[3] $sc[4] $sc[6] $yjm[6]\n”; 

   } 

}