[英]Array elements are not printed in Perl
I have two sets of files. 我有两套文件。 One file gives a list of gene names (one gene per line).
一个文件列出了基因名称列表(每行一个基因)。 The second file has a list of gene pairs (eg, => '1,2' and one gene pair perl line).
第二个文件具有一列基因对(例如=>'1,2'和一个基因对perl行)。 The gene names are numerical.
基因名称是数字。 I want to list all possible gene combinations except the known gene pairs.
我想列出除已知基因对以外的所有可能的基因组合。
My output should be: 我的输出应为:
3,4
4,5
6,7
...
...
But, I get something like this => 但是,我得到这样的东西=>
,4
,5
,7
All the first elements do not print. 所有第一个元素都不打印。 I'm not sure exactly what's wrong with the code.
我不确定代码到底有什么问题。 Can anyone help?
有人可以帮忙吗?
My code: 我的代码:
#! 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";
}
}
Your file uses CR LF for line endings, but you're on a system that uses LF for line endings, so your program outputs 您的文件使用CR LF作为行尾,但是您在使用LF作为行尾的系统上,因此程序输出
"3" <CR> "," "4" <CR> <LF>
which your terminal shows as 您的终端显示为
,4
Either fix the line endings using 可以使用以下方式修复行尾
dos2unix inputfile
Or change 或改变
chomp(@e_file);
chomp(@k_file);
to 至
s/\s+\z// for @e_file;
s/\s+\z// for @k_file;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.