Scarborough has asked for the wisdom of the Perl Monks concerning the following question:

Hi Venerable Monks.

I have written a program which reads data about programs which need to be run on a specific day and creates a perl script which runs the program with multiple system calls.

My problem is that the program can take up to three arguments but not every time. The arguements are name always required date optional run optional . What I need to implement is some type of switch arguements
 perl create_script.pl -n amroeve01 -r RUN
Can anyone point me in the direction of some tips on how to implement this.
Thanks

Replies are listed 'Best First'.
Re: A smart way to handle @ARGV
by tachyon (Chancellor) on Jul 08, 2004 at 09:06 UTC

    You can use:

    1. Getopt::Std Getopt::Long or any of the other Getopt:: modules
    2. use the -s argument the invokes perls native ARGV parsing.
    3. hand parse @ARGV (ick)

    I have grown to like -s due to its simplicity. BrowserUk introduced to me to it. Here is a short example:

    #!/usr/bin/perl -sw use strict; our $FILE; our $CAT ||= 79; our $VERBOSE ||= 1; die "Usage: $0 -FILE=list [-CAT=$CAT] [-VERBOSE=$VERBOSE]\n" unless $FILE and -f $FILE;

    cheers

    tachyon

      Thanks for this I think this should solve my problem.
Re: A smart way to handle @ARGV
by ccn (Vicar) on Jul 08, 2004 at 09:05 UTC
Re: A smart way to handle @ARGV
by gellyfish (Monsignor) on Jul 08, 2004 at 09:06 UTC

    There are a number of modules for handling command line arguments including:


    Both of the above are part of the core perl distribution.

    /J\

Re: A smart way to handle @ARGV
by Anonymous Monk on Jul 09, 2004 at 12:12 UTC
    use Getopt::Std;
Re: A smart way to handle @ARGV
by Anonymous Monk on Jul 12, 2004 at 13:01 UTC
    Take a look at the PM Getopts::Std. It is designed to do exactly what you are looking for.