Re: beginner trying to use Getopt::Long
- From: Jim Gibson <jgibson@xxxxxxxxxxxxxxxxx>
- Date: Thu, 12 Oct 2006 13:36:22 -0700
In article <1160679520.565760.58640@xxxxxxxxxxxxxxxxxxxxxxxxxxxx>,
markpark <mark.leeds@xxxxxxxxxxxxxxxxx> wrote:
I was hoping that someone could help me. I'm new to the list and I'm at
a job
and kind of under pressure and don't know who else to ask.
I new at perl and I wrote a short program to read values from the
command line and then
just output them into a hash. i've grinded through the documentation
and books and wrote
something but it's not quite working. its close though.
I couldn't find a way to attach files so I've included the code below
and then how one would
run the program with various values at the command line ( actually they
aren't options.
they are required ).
#------------------------------------------------------------------------------
------------------------------------------------
#!/ms/dist/perl5/bin/perl5.6
use strict;
use Getopt::Long;
my($DRIVER_FILE,$START_DATE,$END_DATE,$START_TIME,$END_TIME,$CURRENCY,$EXCHANG
E,$DATA_DIR,$OUT_FILE);
my %dict= ('driverfile' => \$DRIVER_FILE, 'startdate' => \$START_DATE,
'enddate=' => \$END_DATE, 'starttime=' => \$START_TIME, 'endtime=' =>
\$END_TIME, 'currency' => \$CURRENCY, 'exchange' => \$EXCHANGE,
'datadir' => \$DATA_DIR, 'outfile' => \$OUT_FILE);
GetOptions(\%dict,'driverfile=s','startdate=s','enddate=s','starttime=s','endt
ime=s','currency=s','exchange=s','datadir=s','outfile=s');
if (!exists($dict{"startdate"}) ) {
die " program requires startdate argument \n";
[rest snipped]
Your use of GetOptions is incorrect. Command line values are placed in
$DRIVER_FILE, etc, not the %dict hash. Read 'perldoc Getopt::Long';
use strict;
use warnings;
use Getopt::Long;
my($DRIVER_FILE,$START_DATE);
GetOptions(
'driverfile=s' => \$DRIVER_FILE,
'startdate=s' => \$START_DATE
);
if ( ! defined $START_DATE ) {
die " program requires startdate argument \n";
}
print "$DRIVER_FILE\n";
print "$START_DATE \n";
__END__
Please post short-as-possible programs. Your problem can be
demonstrated with only one variable.
.
- References:
- beginner trying to use Getopt::Long
- From: markpark
- beginner trying to use Getopt::Long
- Prev by Date: Re: beginner trying to use Getopt::Long
- Next by Date: Re: Socket error
- Previous by thread: Re: beginner trying to use Getopt::Long
- Next by thread: FAQ 1.7 How stable is Perl?
- Index(es):
Relevant Pages
|