Beefy Boxes and Bandwidth Generously Provided by pair Networks
Just another Perl shrine
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??

This is of course all style - the best programs are those that actually run. You certainly shouldn't worry about refactoring working code, and if any of these ideas go against what has worked for you, take them with a grain of salt.

By limiting the scope of variables to the smallest range possible, you reduce the possibility of misusing those variables. Following what you posted, I would have written it as:

#_ Check for minimum number of command line argument variables if($#ARGV < 6) { Usage(); print "NOT ENOUGH COMMAND LINE ARGUMENTS\n"; exit 0; } #_ Command line options & setup filenames my($alignment_file, $scorecons_file, $image_file, $numbered_model, $cs +a_file); foreach my $i (0 .. $#ARGV) #for ($i=0; $i<=$#ARGV; $i++) { if($ARGV[$i] eq "-a") { $alignment_file = $ARGV[$i+1]; } if($ARGV[$i] eq "-s") { $scorecons_file = $ARGV[$i+1]; } if($ARGV[$i] eq "-i") { $image_file = $ARGV[$i+1]; } if($ARGV[$i] eq "-m") { $numbered_model = $ARGV[$i+1]; } if($ARGV[$i] eq "-c") { $csa_file = $ARGV[$i+1]; } } if (not defined $csa_file) { Usage(); print "No CSA file defined\n"; exit 0; } print "test $csa_file\n"; my $fh_csa = new FileHandle($csa_file, "r") or die "Cannot open CSA file: $csa_file ($!)";

I've made a few changes here. First, I moved your argument count to before you attempt to parse your argument list since that is a more basic test. Second, I swapped to a foreach loop, and declared $i to be scoped to that loop. Since an iterator is localized to a loop anyway, it is essentially a separate variable already - giving it a unique name makes this more explicit. If your _file variables all behave like script globals, I agree that they should be declared as early as possible in your script. If they only have meaning in the context of the command line arguments and some file handles, then it is a good idea to declare them near to where they get their values, so no one attempts to use them before they are defined. This is also why I added a my to your file open.


In reply to Re^5: Use of uninitialized value in concatenation (.) or string error after adding new arguement on command line by kennethk
in thread Use of uninitialized value in concatenation (.) or string error after adding new arguement on command line by Angharad

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • Are you posting in the right place? Check out Where do I post X? to know for sure.
  • Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
    <code> <a> <b> <big> <blockquote> <br /> <dd> <dl> <dt> <em> <font> <h1> <h2> <h3> <h4> <h5> <h6> <hr /> <i> <li> <nbsp> <ol> <p> <small> <strike> <strong> <sub> <sup> <table> <td> <th> <tr> <tt> <u> <ul>
  • Snippets of code should be wrapped in <code> tags not <pre> tags. In fact, <pre> tags should generally be avoided. If they must be used, extreme care should be taken to ensure that their contents do not have long lines (<70 chars), in order to prevent horizontal scrolling (and possible janitor intervention).
  • Want more info? How to link or How to display code and escape characters are good places to start.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others sharing their wisdom with the Monastery: (6)
As of 2024-04-18 13:11 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found