Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: misbehaving program

by tlm (Prior)
on Apr 20, 2005 at 13:11 UTC ( #449579=note: print w/ replies, xml ) Need Help??


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


Comment on Re: misbehaving program
Select or Download Code
Re^2: misbehaving program
by BazB (Priest) on Apr 22, 2005 at 23:48 UTC

    My brain doesn't cope well with

    system("command") and die "Error message: $?";

    Although the above is perfectly valid - as system returns zero for success, unlike every other perl function I can think of - I'd much rather use:

    system("command") == 0 or die "Error message: $?";
    ...which makes it much more obvious (at least to me) what's going on.

    Although I note that the examples in the perldoc use the latter approach, this is mostly a personal style point/grumble: feel free to ignore it.


    If the information in this post is inaccurate, or just plain wrong, don't just downvote - please post explaining what's wrong.
    That way everyone learns.

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://449579]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (7)
As of 2014-12-25 10:15 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    Is guessing a good strategy for surviving in the IT business?





    Results (160 votes), past polls