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"
In reply to Getopt::Std dies or returns empty var by bonoboy
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |