bonoboy has asked for the wisdom of the Perl Monks concerning the following question:
For some reason I'm unable to get the simplest getopt functionality to work. I'm fine with Getopt::Long, but Getopt::Std for some reason isn't doing what I think it should:
eg:
#!/usr/local/bin/perl -w use strict; use Getopt::Std; my $opt_u = 0; getopt('u') || die "can't do getopt\n"; print "username is $opt_u\n";
This ALWAYS dies. If I don't use die, it just returns an empty variable. It seems to be me misunderstanding how to declare the variable while using strict. Without declaring the variable, the script won't run. But the only way to get it to run is to not use strict and not declare it.
###Ok, I've played round and found the solution is to declare it within the package. Like so:
#!/usr/bin/perl -w use strict; use Getopt::Std; $Getopt::Std::opt_u = 0; getopt('u'); print "username is $Getopt::Std::opt_u\n";
Thanks for the help, everyone.
janitored by ybiC: Retitle from less than descriptive "dumbass strict / getopt questions"
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Getopt::Std dies or returns empty var
by derby (Abbot) on Mar 11, 2004 at 13:10 UTC | |
by bonoboy (Sexton) on Mar 11, 2004 at 13:14 UTC | |
by grinder (Bishop) on Mar 11, 2004 at 13:50 UTC | |
|
Re: Getopt::Std dies or returns empty var
by Happy-the-monk (Canon) on Mar 11, 2004 at 13:07 UTC | |
|
Re: Getopt::Std dies or returns empty var
by matija (Priest) on Mar 11, 2004 at 13:11 UTC | |
by Abigail-II (Bishop) on Mar 11, 2004 at 13:35 UTC |