As others have said, GetOpt (Standard or Long) is a good thing to learn, but sometimes, when doing something quick and easy, I just work directly with @ARGV; if all you want is a "-v" or "--version" option, then here's a way to avoid the warning about "uninitialized value in string eq" (which is not an error -- just a warning, because you've asked for warnings):
Of course, when you need a script to handle multiple options (and especially if you might add more to it as time goes by), you'll want to spend the time to learn one of the Getopt modules. If you don't, you'll be spending about the same amount of time writing a while loop with lots of "if ... elsif ... else ..." stuff for each new script that uses multiple options.sub version { print "whatever\n"; } version if ( @ARGV and shift =~ /^--?v(?:ersion)?$/ ); # ...
BTW, I think having both "-w" and "use warnings" is redundant. The "perllexwarn" man page describes the latter as a replacement for the former.
In reply to Re: how add option to my program?
by graff
in thread how add option to my program?
by white-fox
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |