http://www.perlmonks.org?node_id=449579


in reply to misbehaving program

As others have pointed out you are not running under use strict and use warnings, and you are not checking the return status of your system calls. For the latter you should at least have something like

system("dsspcmbi $pdbstructure $dsspfile") and die "System called fail +ed.";
to alert you that something went awry, and where. (Note that system is the unusual Perl function that returns a true value upon failure, hence the and clause to check for failure.)

Next, the line

$residuecombofile = "$combodir$residue1$residue2$residue3$out";
is executed redundantly at a couple of places throughout the program (as far as I can tell, the RHS always evaluates to the same value); moreover, $residue1, $residue2, and $residue3 are undefined. (BTW, on the naming of variables, you may want to read this node.) In your post you refer to "OUTFILE's" but it is clear that this program will generate at most one OUTFILE, whose name is the constant value of $residuecombofile.

You open a file handle PDB with this line

if(open(PDB,"$pdbstructure"))
but you don't do anything with the handle. If all you want to do is check for the existence of this file, use
if ( -e $pdbstructure )
or better yet
if ( -r $pdbstructure )
(See file test operators). Furthermore, if the open cited above fails once, then it sets $flag, which would stay set, since it is never reset back to 0 anywhere (in fact, this variable is never properly initialized outside of the loop); this means that, after one failure of the open, the then clause of the if statement beginning with
if($flag == 0)
would never again be executed, even if subsequent calls calls to open(PDB,"$pdbstructure") structure succeed. (BTW, the idiomatic way to make the test above is unless ( $flag ).) Do you ever see the message
No structure file. Moving to next structure in list
?

the lowliest monk