Arrays 数组元素不是用Perl打印的
我有两套文件。一个文件给出了一个基因名称列表(每行一个基因)。第二个文件有一个基因对列表(例如,=>'1,2'和一个基因对perl行)。基因名称是数字的。我想列出所有可能的基因组合,除了已知的基因对 我的输出应该是:Arrays 数组元素不是用Perl打印的,arrays,perl,printing,newline,Arrays,Perl,Printing,Newline,我有两套文件。一个文件给出了一个基因名称列表(每行一个基因)。第二个文件有一个基因对列表(例如,=>'1,2'和一个基因对perl行)。基因名称是数字的。我想列出所有可能的基因组合,除了已知的基因对 我的输出应该是: 3,4 4,5 6,7 ... ... 但是,我得到这样的东西=> ,4 ,5 ,7 所有第一个元素都不会打印。我不确定代码到底出了什么问题。有人能帮忙吗 我的代码: #! usr/bin/perl use strict; use warnin
3,4
4,5
6,7
...
...
但是,我得到这样的东西=>
,4
,5
,7
所有第一个元素都不会打印。我不确定代码到底出了什么问题。有人能帮忙吗
我的代码:
#! usr/bin/perl
use strict;
use warnings;
if (@ARGV !=2) {
die "Usage: generate_random_pairs.pl <entrez_genes> <known_interactions>\n";
}
my ($e_file, $k_file) = @ARGV;
open (IN, $e_file) or die "Error!! Cannot open $e_file\n";
open (IN2, $k_file) or die "Error!! Cannot open $k_file\n";
my @e_file = <IN>; chomp (@e_file);
my @k_file = <IN2>; chomp (@k_file);
my (%known_interactions, %random_interactions);
foreach my $line (@k_file) {
my @array = split (/,/, $line);
$known_interactions{$array[0]} = $array[1];
}
for (my $i = 0; $i <= $#e_file; $i++) {
for (my $j = $i+1 ; $j <= $#e_file; $j++) {
if ((exists $known_interactions{$e_file[$i]}) && ($known_interactions{$e_file[$i]} == $e_file[$j])) {next;}
if ((exists $known_interactions{$e_file[$j]}) && ($known_interactions{$e_file[$j]} == $e_file[$i])) {next;}
print "$e_file[$i],$e_file[$j]\n";
}
}
#!usr/bin/perl
严格使用;
使用警告;
如果(@ARGV!=2){
die“用法:生成\u random\u pairs.pl\n”;
}
我的($e_文件,$k_文件)=@ARGV;
打开(在$e_文件中)或死亡“错误!!无法打开$e_文件\n”;
打开(IN2,$k_文件)或死亡“错误!!无法打开$k_文件\n”;
我的@e_文件=;chomp(@e_文件);
我的@k_文件=;chomp(@k_文件);
我的%(已知交互作用%、随机交互作用%);
foreach my$行(@k_文件){
my@array=split(/,/,$line);
$known_interactions{$array[0]}=$array[1];
}
对于(my$i=0;$i,您的文件使用CR LF作为行尾,但您所在的系统使用LF作为行尾,因此您的程序输出
"3" <CR> "," "4" <CR> <LF>
或者使用
dos2unix inputfile
或改变
chomp(@e_file);
chomp(@k_file);
到
您的文件使用CR LF作为行尾,但您所在的系统使用LF作为行尾,因此您的程序输出
"3" <CR> "," "4" <CR> <LF>
或者使用
dos2unix inputfile
或改变
chomp(@e_file);
chomp(@k_file);
到
你能展示一些输入文件的例子吗?每行2-3行?Ikegami解决了这个问题。但是,这里仍然是格式。对于entrez=>1\n 2\n 3\n已知交互=>1,2\n 2,3\n 4,5\n这是应该的,但它是1\r\n 2\r\n 3\r\n和1,2\r\n 2,3\r\n 4,5\r\n你能展示一些输入文件的例子吗?每行2-3行Ikegami fixed问题。但格式仍然是这样的。对于entrez=>1\n 2\n 3\n对于已知的交互=>1,2\n 2,3\n 4,5\n这是应该的,但它是1\r\n2\r\n3\r\n和1,2\r\n2,3\r\n4,5\r\n