这是给我带来问题的代码。错误显示为语法错误,但我无法弄清楚它在哪里或是什么?它说错误是在'while open(FILE,$ array [$ i])'语句中,但是我看不出有什么问题。
#! /usr/bin/perl -w
$splitpdb_version = '0.01' ;
use File::Basename;
$true = 1 ;
$false = 0 ;
use Getopt::Std ;
$opt_h = 0 ;
$opt_s = 0 ;
$i = 0;
getopts ('hs') ;
$help = $opt_h ;
$strip = $opt_s ;
@array = <top8000_fullProteins_meso/*.pdb>
while open (FILE, $array[$i])
{
$pdbfile = $array[$i] ;
$string = "$array[$i]" ;
$filename = fileparse($string);
if (! $pdbfile || $help) {
print STDERR "\n";
print STDERR "Usage: \"splitpdb [-hs] pdbfile.pdb\"\n\n";
if (! $help) {
exit ;
}
}
if (! $pdbfile) {
print "-h flag gets this help message\n" ;
print "-s flag strips header lines\n" ;
exit ;
}
open (PDBFILE, $pdbfile) or die "Could not open file \"$pdbfile\"" ;
%chains = () ;
@header = () ;
$header_done = $false ;
$lastchain = $false ;
$atoms = [] ;
while () {
$atom = <PDBFILE> ;
if (! $atom) {
if ($lastchain) {
$chains{$chain} = $atoms ;
last;
}
}
if (($atom =~ /^ATOM/i) | ($atom =~ /^HETATM/i)) {
$header_done = $true ;
$chain = substr $atom, 21, 1 ;
if (! $lastchain) {
$lastchain = $chain ;
}
if (lc($chain) eq lc($lastchain)) {
push @{$atoms}, $atom ;
} else {
$chains{$lastchain} = $atoms ;
$atoms = [] ;
$lastchain = $chain ;
push @{$atoms}, $atom ;
}
} else {
if (! $header_done) {
push @header, $atom ;
}
}
}
close (PDBFILE);
$chainno = 0 ;
foreach $chain (keys %chains) {
$chainno++ ;
open (PDBOUT, ">$filename$chain$chainno.pdb") ;
@atoms = @{$chains{$chain}} ;
$lineno = 0 ;
$atomno = 0 ;
if (! $strip) {
foreach $line (@header) {
print PDBOUT $line ;
}
}
while ($atoms[$lineno]) {
if (($atoms[$lineno] =~ /^ATOM/i) | ($atoms[$lineno] =~ /^HETATM/i)) {
$atomno++;
$atomnostr = sprintf "%4d", $atomno;
$atoms[$lineno] =~ s/^(.{7}).{4}/$1$atomnostr/ ;
}
print PDBOUT $atoms[$lineno] ;
$lineno++;
}
close PDBOUT ;
}
printf ("There were %d chains.\n\n", (scalar keys %chains));
$i++;
};
答案 0 :(得分:2)
第19行在结尾处缺少一个分号。如上所述,use strict
可能会发现其他错误,但缺少的分号可能是您收到语法错误的原因。