Look at all the trival errors people have made in their replies, and you'll see why configuring the program with bare command line arguments is a poor way to do things. If you are writing a quick 10-liner to get something done quickly, it might be reasonable to use this method, but for any longer program, better solutions exist. The best way is to use flags to name the arguments; then you can skip arguments which should use the default value, or specify them in whatever order is convenient or natural at the time, rather than being forced by the hard-coded ordering.
I would suggest using Getopt::Long ... and if this is a longer program, you'll have builtin documentation, of course:
use warnings; use strict; use Getopt::Long; use Pod::Usage; my %options = ( based_on => 'tp', top => 1 ); GetOptions( \%options, 'based_on=s', 'top=i', 'man', 'help', ) || pod2usage(2); pod2usage(1) if $options{'help'}; pod2usage( '-verbose' => 2 ) if $options{'man'};
Then you invoke your program as:
%> myprog -based_on sn -top 5 # or as %> myprog -top 3 -based_on sn #or you can use the automaticly provided abbreviation recognition ... %> myprog -base sn -t 2 # or use tht default values %> myprog
There are ways to specify default values in the GetOPtions arguments, but I prefer to specify them by initializing %options.
While you are at it, you can specify within the file that the program should be run using Perl. In Unix, make the very first line:
#!/usr/bin/perl
or whatever the correct path is on your system. There's a similar, two line solution for Windows; I believe it's given in the Perl documention. Type:
perldoc perltoc
and spend the next three days reading.
--
TTTATCGGTCGTTATATAGATGTTTGCA
In reply to Processing Command Line Arguments
by TomDLux
in thread Ternary Operator for Multiple Arguments Passing
by neversaint
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |