Perl子程序
我在执行 Perl 子例程时遇到问题。 这是定义:
sub primer{
print STDERR "primer is $_[0]\n";
$primer=$_[0];
if ($_[0]=~/ATTACCGC/){
mkdir ("Primer1") || die "Unable to create directory <$!>\n";
open OUTFILE1,">","Primer1/lt450";
open OUTFILE2,">","Primer1/no_primer_lt450";
open REPORT,">","Primer1/Report";
&primer_analysis('ATTACCGC');}
if ($_[0]=~/CCGTCAATTC[AC]/){
mkdir ("Primer2") || die "Unable to create directory <$!>\n";
open OUTFILE1,">","Primer2/lt450";
open OUTFILE2,">","Primer2/no_primer_lt450";
open REPORT,">","Primer2/Report";
&primer_analysis('CCGTCAATTC[AC]');}
这是上面应该调用的另一个子例程的一部分:
sub primer_analysis{
$primer=$_[0];
while ($line = <INFILE>){
if ($line =~ /^>/) {
$header = $line;
$headcnt++;}
if ($line !~/^>/){
$seq = $line;
chomp($seq);
if (length($seq)<450 && $seq=~/^$primer/){
$len_450=length($seq);
$TB_450=$len_450+$TB_450;
$cnt450++;
print OUTFILE1 "$header";
print OUTFILE1 "$seq\n";}}
以下是调用该函数:
&primer('ATTACCGC');
&primer('CCGTCAATTC[AC]');
问题是,当我运行程序时,仅执行 Primer1,即正确创建目录和数据,但是没有任何反应到入门2。 有什么想法为什么只执行函数的一部分吗? 谢谢
I am having trouble with execution of my perl subroutines.
Here is the definition:
sub primer{
print STDERR "primer is $_[0]\n";
$primer=$_[0];
if ($_[0]=~/ATTACCGC/){
mkdir ("Primer1") || die "Unable to create directory <$!>\n";
open OUTFILE1,">","Primer1/lt450";
open OUTFILE2,">","Primer1/no_primer_lt450";
open REPORT,">","Primer1/Report";
&primer_analysis('ATTACCGC');}
if ($_[0]=~/CCGTCAATTC[AC]/){
mkdir ("Primer2") || die "Unable to create directory <$!>\n";
open OUTFILE1,">","Primer2/lt450";
open OUTFILE2,">","Primer2/no_primer_lt450";
open REPORT,">","Primer2/Report";
&primer_analysis('CCGTCAATTC[AC]');}
Here is part of another subroutine that should be invoked by above:
sub primer_analysis{
$primer=$_[0];
while ($line = <INFILE>){
if ($line =~ /^>/) {
$header = $line;
$headcnt++;}
if ($line !~/^>/){
$seq = $line;
chomp($seq);
if (length($seq)<450 && $seq=~/^$primer/){
$len_450=length($seq);
$TB_450=$len_450+$TB_450;
$cnt450++;
print OUTFILE1 "$header";
print OUTFILE1 "$seq\n";}}
And following is calling the function:
&primer('ATTACCGC');
&primer('CCGTCAATTC[AC]');
problem is that when I run the program only the Primer1 gets executed i.e. directories and data is properly created, however, nothing happens to Primer2.
Any ideas why only one part of the function is getting executed?
Thanks
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
字符
[]
是正则表达式中的特殊字符。您需要在子引物中通过编写 CCGTCAATTC\[AC\] 来转义它们,或者简单地使用eq
字符串比较。事实上,您的第二个 if 失败,因为底漆中的文字[
与[AC]
字符类不匹配。the characters
[]
are special characters in regular expressions. You need to escape them in sub primer by writingCCGTCAATTC\[AC\]
, or simply use theeq
string comparison. As is, your second if is failing because the literal[
in your primer does not match the[AC]
character class.一般建议:
考虑使用shift代替$_[0],即
而不是
...然后在函数中使用 $primer 而不是 $_[0]。
General advice:
Consider using shift instead of $_[0], i.e.
instead of
...and then use $primer instead of $_[0] in your function.