use strict; use warnings; my $annotation =' '; my $dna =' '; my $record =' '; my $save_input_separator =$/; open (DNAFILENAME,'f:\\perl\\strawBerry.gb')||die("can not open the file!"); $/ = "//\n"; $record = <DNAFILENAME>; ($annotation,$dna) = ($record=~/^(LOCUS.*ORIGIN\s*\n) (.*)\/\/\n/s); print "$annotation \n\n\n$dna\n";
这里面关键就是用到了模式匹配:
($annotation,$dna) = ($record=~/^(LOCUS.*ORIGIN\s*\n) (.*)\/\/\n/s);
这一行表示,如果在$record中可以匹配到(Locus.*ORIGIN\s*\n) 和(.*) 那么就将第一个括号中的数值赋给$annotation,把第二个括号中匹配的内容赋给$dna.