On Wed, Aug 15, 2001 at 02:49:34PM -0700, pn wrote:
> #/usr/bin/perl -w
> use strict;
>
> ##### Forward declarations
>
> my $opt_help;
This is your problem right here. Getopt::Long sets the package global
$main::opt_help, but now that you've declared the variable lexical, anytime
you access it unqualifed in your program you'll get the lexical variable.
The solution is to either declare it global, with our or use vars, or pass
in a variable to GetOptions. E.g.
our $opt_help;
GetOptions('help|h');
OR
use vars qw($opt_help);
GetOptions('help|h');
OR
GetOptions('help|h' => \$opt_help);
OR (my preference)
GetOptions(\%opts, 'help|h'); # now available as $opts{'help'}
Some further commentary is below.
> sub GetCmdLine;
>
> ##### Begin of Main Body
>
> &GetCmdLine();
>
> ##### End of Main Body
>
> ##########################
> #### Sub GetCmdLine ####
> ##########################
>
> sub GetCmdLine {
>
> use Getopt::Long;
It's generally better to place use lines near the beginning of the file;
that's, conceptually, when they get executed, regardless of their position
in the code, and it provides an easy way for someone to determine the
dependencies your code has.
> $Getopt::Long::ignorecase;
> $Getopt::Long::autoabbrev;
I don't know what you intend to accomplish with these. You're simply
mentioning the variables, you aren't assigning any values to them.
>
> &GetOptions("help|h");
>
> ##### Print the value of $opt_help
> print "The value of \$opt_help is : ",
> $opt_help, "\n";
>
> if (defined($opt_help) && ($opt_help ==1)) {
It's easier to test simply for truth:
if ($opt_help) {
> print "\n\nUsage: $0 [options] \n";
> print " [optins]:\n";
> print "\t\t-h Prints this help message
> header.....\n";
>
> }
> }
Michael
--
Administrator www.shoebox.net
Programmer, System Administrator www.gallanttech.com
--
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]