perl 应用求助:一对多变为一对一
发布网友
发布时间:2022-07-29 20:07
我来回答
共2个回答
热心网友
时间:2023-11-30 10:49
while ( chomp ( my $line = <DATA> ) ) {
my ( $head, @list ) = split /[\s\,]+/, $line;
print "$head $_$/" foreach @list;
}
__DATA__
strophanthidin CREBBP,HIF1A,CREB1,EP300,CEBPA,CEBPB,SP1,
digoxin CREBBP,CREB1,RPS6KA5,EP300,CEBPA,RPS6KA1,SP1,
hydrastinine NCOA2,CREB1,
puromycin CREBBP,HIF1A,CREB1,CEBPA,CEBPB,
procaine MYOD1,
proscillaridin CREBBP,NCOA2,CREB1,RPS6KA5,EP300,CEBPA,
helveticoside CARM1,CREB1,RPS6KA5,EP300,CEBPA,CEBPB,SP1,
staurosporine CREBBP,CREB1,EP300,CEBPB,
lanatoside_c CREBBP,NCOA2,CREB1,RPS6KA5,EP300,CEBPA,SP1,
digoxigenin CREBBP,NCOA2,CREB1,RPS6KA5,EP300,CEBPA,
热心网友
时间:2023-11-30 10:49
#!/usr/bin/perl -w
use strict;
die "perl $0 <inputfile.txt>\n" unless(@ARGV == 1);
open IN,$ARGV[0];
while(<IN>){
chomp;
my @tmp=split /[ \t,]+/,$_;
for(my $i = 1;$i <@tmp;$i++){
print $tmp[0],"\t",$tmp[$i],"\n";
}
}
close IN;
上面代码保存为run.pl
假设你原始文件名 a.txt 命令行下面输入 perl run.pl a.txt 运行即可