Re: beginner trying to use Getopt::Long



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.
.



Relevant Pages

  • How can I reset the error counter displayed by "netstat -i" [Virus checked HSH Nordbank]
    ... I want to monitor the errors on the interfaces of some SUN Solaris servers. ... But i could not find a way or command to reset this counters to zero. ... Zugriff oder unbefugte Weiterleitung, die Fertigung einer Kopie, die ... Vervffentlichung oder sonstige in diesem Zusammenhang stehende Handlung ist ...
    (SunManagers)
  • Re: Changing records by query?
    ... Below is code that exists in a command button. ... >>Both records have a StartDate and an EndDate. ... > Private Sub Form_Current ...
    (microsoft.public.access.formscoding)
  • Re: Newbie "undefined value"
    ... > used strict and -w. ... From that same command line, if I pass in parameters, ... > to print to a file and using parts of Stein's guestbook script. ... > sub write_datafile { ...
    (comp.lang.perl.misc)
  • Re: Windows/Macro Language Info?
    ... ueber Re: Windows/Macro Language Info? ... Also there was a command line version with ... "Die Interessen der Nation lassen sich nicht anders formulieren als unter ...
    (comp.lang.cobol)
  • Re: My FIRST Class!! But it doesnt work as expected - please HELP!
    ... _generator As New Random ... class as part of the Dim myObject as New Die command. ... common throughout instantiation of a class THEN you used the SHARED ...
    (microsoft.public.dotnet.languages.vb)