2015-07-06 44 views
0

,因爲需要根據長度差異(693至 712)進行打印,如同在所有序列中提到的一樣。如果我輸入的長度爲 20應該只打印不同的序列20,如果我輸入的文本框的值爲20,並且下拉選擇大於它應該打印的長度匹配大於二十的匹配的長度。如何在文本框中打印指定輸入的長度爲

example.txt中

GGATCACGAGGTCAGGAGAT (693 TO 712) ATCTCCTGACCTCGTGATCC (3223 TO 3242) 
CAAAAAAAAAAAAAAAAAAA (917 TO 936) TTTTTTTTTTTTTTTTTTTG (2998 TO 3017) 
GAAACCCCGTCTCTACTAAAAATACAAAAAA (737 TO 767) TTTTTTGTATTTTTAGTAGAGACGGGGTTTC (3168 TO 3198) 

perl的

#!usr/local/bin/perl 
open(IN,"/home/httpd/cgi-bin/r/example.txt")|| die("Cannot open file"); 
while(<IN>) 
{ 
    if($_ =~ /^\w+\s+\((\d+)\s+[to]+\s+(\d+)\)/i) 
    { 
     $data=$_; 

     $num1=$1; 
     $num2=$2; 
     $diff=($num2-$num1)+1; 
     $str="a".$diff; 
     #print $str; 
     push(@$str,$data); 
    } 
} 

回答

0

我不知道你是如何從客戶端獲取價值,爲什麼你用$diff串聯"a"$diff加1,但如果從命令行提供值,它將很好地工作。

這些值存儲在散列而不是數組中。

#!/usr/bin/perl 
use strict; 
use warnings; 
use Data::Dumper; 

open my $fh, '<', 'example.txt' or die "unable to open file: $!"; 
my %hash; 
while(<$fh>){ 
my @seq=split(/\)\s+/,$_); 
foreach(@seq) 
    { 
$_=$_.") "; 
#print $_; 
if($_ =~ /(\d+)\s*TO\s*(\d+)/i){ 
     my $num1=$1; 
     my $num2=$2; 
my $diff=($num2-$num1)+1; 
$hash{$_}=$diff; 

    } 
} 
} 
close($fh); 
#print Dumper(\%hash); 
print "enter the number: \n"; 
chomp(my $num=<>); 
if($num == 20){ 
foreach(keys %hash){ 
print "$_ => $hash{$_} \n" if($hash{$_} == 20); 
} 
} 
elsif($num > 20){ 
foreach(keys %hash){ 
print "$_ => $hash{$_} \n" if($hash{$_} > 20); 
} 
} 
相關問題