+ -
当前位置:首页 → 问答吧 → 求助一程序

求助一程序

时间:2011-01-05

来源:互联网

有两个文件,分别是list.txt与input.txt。

list.txt放的文件如下(部分):
CLOCK        CLOCK        9575
PPARD        PPARD        5467
DSG4        DSG4        147409
PTGER3        PTGER3        5733
NUP35        NUP35        129401

文件共三列,第一和二列相同,第三列对应相应的数字


input.txt放的文件如下(部分):
147409
9575
129401


input.txt只有一列,如果input.txt里的数字与list.txt里的数字相同则输出list.txt 文件里相应的值并保存到result.txt文件中


如上面的列子应该输出
DSG4
CLOCK
NUP35



我把list.txt,input.txt,以及两者应该得到的结果以附件形式列上去。

test.rar (9.51 KB)

下载次数:1

2011-01-05 10:51

作者: bioinfor   发布时间: 2011-01-05

发错地方了 sorry  编辑掉

作者: lkk2003rty   发布时间: 2011-01-05

本帖最后由 x9x9 于 2011-01-05 11:34 编辑
  1. use strict;
  2. use warnings;

  3. open LIS,"<list.txt" or die "can't open file:$!";
  4. open INP,"<input.txt" or die "can't open file:$!";
  5. open RES,">result.txt" or die "can't creat file:$!";

  6. chomp(my @arr=<INP>);
  7. close INP;

  8. foreach my $list (@arr){
  9. while (<LIS>){
  10. chomp;
  11. my ($x,$y,$z) =split;
  12. print RES $x."\n" if $list eq $z;
  13. }
  14. }

  15. close LIS;
  16. close RES;
复制代码

作者: x9x9   发布时间: 2011-01-05