Beefy Boxes and Bandwidth Generously Provided by pair Networks
Pathologically Eclectic Rubbish Lister

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

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

Replies are listed 'Best First'.
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?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://449579]
[LanX]: 20 years ago traders were complaining about the latency of the trading system...
[ambrus]: I'm currently in the process of rewriting my proof of concept programs. They sort of developped organically as I was experimenting, so now I've got an ugly mess of multiple programs and one-liners held together by nothing. I'll have to rewrite them to som
[ambrus]: ething that's both cleanly organized and mostly automated.
LanX in train, bad connection
[Corion]: ambrus: Yeah - we're in that situation too, except that there is no time to do the reorganizing :-/
[LanX]: ... so my boss started a project with the newest sun servers and invited the traders to come on weekend to test it... and they were so pleased, that they forced him to keep it in production...
[ambrus]: Corion: sure, this is the long-term plan. The short term is that I have to run this ungodly mess to get results from the new input data today.
[Corion]: ambrus: Most of our "automation" is tied to process exit codes and a shell pipeline :-\
[LanX]: ... a week later they realized that one of the databases - which recorded how much the other banks due to this bank - was not correctly plugged

How do I use this? | Other CB clients
Other Users?
Others scrutinizing the Monastery: (16)
As of 2017-03-29 11:49 GMT
Find Nodes?
    Voting Booth?
    Should Pluto Get Its Planethood Back?

    Results (350 votes). Check out past polls.