Hi,

Am passing some command line arguments when running the Perl script. At the moment I am not doing any checking on the values passed from the command line arguments, that is the assumption is they are correct as passed although we need in some cases, some smart dude would want to impress and "complain" that the script is weak and does not check for values of command line arguments. My point is, if it works, that's it, am not writing one with the intention of having someone to test how to make the script fail especially if it is a rush-up scripts that has to be created ASAP.

Anyway, at some stage, I will want to check for values of command line arguments. Below is an excerpt from my script, it is all very rudimentary as I said so, it is a rush-up scripts.

use strict; use POSIX; use File::Basename; use Time::Local; use Benchmark; use DBI; my $BASE_DIR = "E:\\Backup\\Scripts"; my $EXPORT_DIR = "E:\\Backup\\Export"; my $perl_program = $^X; my $perl_script = $0; my $basename = basename($perl_script,".pl"); $ENV{'ORACLEDB_HOME'}= $ARGV[0]; $ENV{'ORACLE_SID'}= $ARGV[1]; ... ... ... and so on for the scripts to do other stuff ... based on the supplied argument ... ... there is no sub-routines of any kind, this script ... just do what it's told to do in a sequence of commands ... :-) ... ...

Now, my question is can I check for the values of the command line arguments via a subroutine? by changing the Perl script as below, I think. Is there any other way?

use strict; use POSIX; use File::Basename; use Time::Local; use Benchmark; use DBI; my $BASE_DIR = "E:\\Backup\\Scripts"; my $EXPORT_DIR = "E:\\Backup\\Export"; my $perl_program = $^X; my $perl_script = $0; my $basename = basename($perl_script,".pl"); sub check_arguments{ ... ... check arguments whether they are valid or not ... } # MAIN sub check_arguments $ARGV[0] $ARGV[1];

One last questions, are all variables global unless defined with my in which case, it is local? Thanks in advance.


In reply to Checking the command line arguments by newbie01.perl

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.