我有一个看起来像这样的输入文件:
AC_000044.1_a_bothflanks_2kb_polyA.4 AAGTATAATAAAAAAAAAAAAGAAA 25 25 69646
AC_000044.1_aa_bothflanks_2kb_polyA.5 AAGTATAATAAAAAAAAATAATTAAAAAAAAAAAAAATAAAAAATAAAATAAAATAAAAATAAAAA 66 91 69644
AC_000044.1_ab_bothflanks_2kb_polyA.5 TATAATAAAAAAAAAAACATTAAAAATAAAAAATAAAAAATAAAAA 46 137 69647
AC_000044.1_ac_bothflanks_2kb_polyA.3 TATAATTAAAAAAAAAAAAAAAAAAAA 27 164 69642
由制表符分隔的5条信息。我想将第5个选项卡中的每个数字与第4个选项卡中的每个数字进行比较,如果它小于或等于我希望它返回第一个选项卡中的数据的数字。
这是我的代码:
#! /usr/bin/perl -w
use strict;
use Cwd;
my $tab_input = $ARGV[0];
my $output = 'output.txt';
my (@trans_id, @seq, @length, @cum_length, @coord);
open (my $INPUT, "<$tab_input") or die "unable to open $tab_input\n";
open (my $OUTPUT, ">$output") or die "unable to open $output\n";
while (<$INPUT>) {
my @tabfile =split ("\t+",$_);
push @trans_id, $tabfile[0];
push @seq, $tab_file[1];
push @length, $tab_file[2];
push @cum_length, $tab_file[3];
push @coord, $tab_file[4];
for (@tabfile) {
if {$tabfile[3] < $tabfile [4]) {
print "$tabfile[0]\n" > $output;
}
}
close $output;
close $tab_input;
print "Tab file parsing complete.\n";
但是,我在第22行(if语句)出现错误,说$ coord和%cum_length需要显式的程序包名称。我已经在代码顶部修改了数组。当我仅使用数组时,为什么在错误代码中返回%'hash'符号。有任何想法吗?
您描述的错误不是由该代码生成的。这是我可以看到的问题列表
您已经声明@tabfile
但正在使用@tab_file
您的陈述中if {$tabfile[3] < $tabfile [4]) {
有一个大括号而不是一个圆括号
您的声明print "$tabfile[0]\n" > $output
应为
print $OUTPUT "$tabfile[0]\n";
同一条语句缺少右括号
close
需要一个文件句柄参数,而不是文件名,因此您的语句close $output
和close $tab_input
应该分别为close $OUTPUT
和close $INPUT
。
我认为它应该看起来像这样
#!/usr/bin/perl
use strict;
use warnings 'all';
open my $out_fh, '>', 'output.txt' or die $!;
while ( <> ) {
my @fields = split;
print $out_fh "$fields[0]\n" if $fields[3] < $fields [4];
}
print "Tab file parsing complete.\n";
本文收集自互联网,转载请注明来源。
如有侵权,请联系 [email protected] 删除。
我来说两句