This is the code that's giving me problems. The error is showing up as a syntactical one, but I can't figure out where or what it is? It says the error is in the 'while open (FILE , $array[$i])' statement , but I can't see what's wrong .
#! /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++;
};