newbie01.perl has asked for the wisdom of the Perl Monks concerning the following question:
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.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Checking the command line arguments
by moritz (Cardinal) on Dec 03, 2009 at 13:02 UTC | |
|
Re: Checking the command line arguments
by BioLion (Curate) on Dec 03, 2009 at 13:27 UTC | |
|
Re: Checking the command line arguments
by cdarke (Prior) on Dec 03, 2009 at 13:23 UTC | |
by moritz (Cardinal) on Dec 03, 2009 at 13:34 UTC |