您现在的位置是:网站首页> 编程资料编程资料
perl比较两个文件字符串的实例代码_perl_
2023-05-26
389人已围观
简介 perl比较两个文件字符串的实例代码_perl_
需求:取文件1中的一行,和文件2中所有的数据进行比较,有相同的保存起来,否则删除。
#!/usr/bin/perl
#use strict;
open(FILE1,"C:/Perl/BX/BX-Users.txt");
open(FILE2,"C:/Perl/BX/BX-Book-Ratings.txt");
open(result1,">C:/perl/BX/BX-Users_result.txt");
my $i=0;
my $j=0;
while((my $bxUser=)&&($i<10))
{
my $userId=substr($bxUser,0,index($bxUser,","));
while(my $rankUser=)
{
my $userIdCmp=substr($rankUser,0,index($rankUser,","));
if(($userId==$userIdCmp)&&($j==0))
{
syswrite(result1,"$bxUser");
$j++;
}
}
$j=0;
$i++;
}
close(FILE1);
close(FILE2);
close(result1);
复制代码 代码如下:
#!/usr/bin/perl
#use strict;
open(FILE1,"C:/Perl/BX/BX-Users.txt");
open(FILE2,"C:/Perl/BX/BX-Book-Ratings.txt");
open(result1,">C:/perl/BX/BX-Users_result.txt");
my $i=0;
my $j=0;
while((my $bxUser=
{
my $userId=substr($bxUser,0,index($bxUser,","));
while(my $rankUser=
{
my $userIdCmp=substr($rankUser,0,index($rankUser,","));
if(($userId==$userIdCmp)&&($j==0))
{
syswrite(result1,"$bxUser");
$j++;
}
}
$j=0;
$i++;
}
close(FILE1);
close(FILE2);
close(result1);
相关内容
- Linux/Unix下安装Perl模块的两种方法分享_perl_
- Perl中chomp和chop的区别介绍_perl_
- perl中chomp的使用介绍(chop和chomp函数区别)_perl_
- 一行代码解决 perl输入 排序 输出问题_perl_
- perl ping检测功能脚本代码_perl_
- perl pop push shift unshift实例介绍_perl_
- perl push的用法及子程序返回值的反思_perl_
- perl子程序的运用及子程序中变量私有(my)声明的重要性_perl_
- perl的格式化输出及chomp的重要性分析_perl_
- perl高级排序,<=>操作符,飞船操作符_perl_
