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

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.