【问题标题】:Script returns false regardless of value无论值如何,脚本都返回 false
【发布时间】:2016-03-07 14:46:38
【问题描述】:

我正在创建一个程序来确认给定的核苷酸序列是否是回文。该脚本创建一个反向补码并将其与原始序列进行比较,确认如果 2 匹配,它是一个回文。问题是我的脚本总是会声明它不是回文,即使它是。

#!/usr/bin/perl
use strict;

print "Enter the sequence\n";
my $seq = <STDIN>;

my $r=reverse($seq);

$r =~ tr/ACTGactg/TGACtgac/;

print "Reverse complement: $r \n";

if ($r eq $seq) {
    print "The sequence is a palindrome\n";
} else {
    print "The sequence is NOT a palindrome\n";
}

预期输出示例:

Enter the sequence:
CG
Reverse complement:
CG
The sequence is a palindrome

【问题讨论】:

    标签: perl string-matching palindrome dna-sequence


    【解决方案1】:

    问题是从&lt;STDIN&gt; 读取后,$seq 还包含最后的换行符。 如果在my $seq = &lt;STDIN&gt;; 行之后添加chomp($seq);,脚本将按预期运行。

    【讨论】:

      猜你喜欢
      • 2018-02-11
      • 2011-12-23
      • 1970-01-01
      • 2012-01-07
      • 1970-01-01
      • 1970-01-01
      • 2021-03-04
      • 2013-11-13
      • 2022-01-12
      相关资源
      最近更新 更多