good chemistry is complicated, and a little bit messy -LW |
|
PerlMonks |
Re: How to use getopts?by bv (Friar) |
on Mar 09, 2010 at 19:25 UTC ( [id://827614]=note: print w/replies, xml ) | Need Help?? |
Your code has some other issues, which I'll get to in a bit, but regarding Getopt, here are some ideas: 1. Call GetOptions early, so that you can validate inputs. You are prompting for input even when the user provides groupDir as an argument. Instead, call GetOptions and then prompt if $groupDir is not set. 2. Check for failure of GetOptions in case the user provided an incorrect option. This is easiest like this: GetOptions('slopefile=s' => \$s) or die "Invalid option"; 3. Take advantage of the Long part of Getopt::Long and use long option names. It won't prevent the user from using something like -s if they want to, but it makes your code (and your documentation) more readable to allow -slopefile. Lastly, a few words about your code in general. You should always use strict; use warnings;. Use the 3-argument form of open, with lexical (my) filehandles, and use or, not || for or die error checking. This would change your code to look like this: open my $userinput, '<', $groupDir or die "Error opening $groupDir: $!";Your use of the ternary operator (?:)could be changed to the more straightforward defined-or assignment operator, //=. If you have an older version of perl than 5.10.0, logical-or ||= may work in most cases, but may cause bugs in others. Best of luck with your program! print map{substr'hark, suPerJacent other l',$_,1}(11,7,6,16,5,1,15,18..23,8..10,24,17,0,12,13,3,14,2,4);
In Section
Seekers of Perl Wisdom
|
|