I hate having to send the same parameters to a script but there are times when you need to vary from your defaults. I came up with this code (using CGI to handle parameter parsing) with the help of a www.perlguru.com user: mhx. You can define a default for your parameters and if the user supplies a value under the same argument name, the users value is used; otherwise your default is used. Insert into your own code if you need this sort of capability. P.S I could only get 'join "&" => @ARGV' to work this way for @ARGV handling even though CGI shuold deal with it directly. Enjoy!
#!/usr/bin/perl # define script defaults (change these to suit your needs or supply th +em in your script calls) my %defaults = ( foo => "bar", bar => "foo", ... => ..., ); # to handle parameter passing use CGI; # get the script parameters; 1st from the ARGV array (in the case of S +SI calls) then the QUERY_STRING if (@ARGV) { $input = new CGI ( join "&" => @ARGV ); } else { $input = + new CGI; } # set the values for parameters omitted by user to the %defaults value +s for ( keys %defaults ) { $input->param(-name=>$_,-value=>$defaults{$_} +) unless $input->param($_); } ######### # the rest of your program here #########

In reply to script call over-ridable defaults by S_Shrum

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.