
askan
Novice
Oct 14, 2009, 9:29 AM
Post #1 of 7
(345 views)
|
|
Working with null values in Perl
|
Can't Post
|
|
Hey guys, I am trying to build some command line options into my word count program. I've been working with the $#ARGV and $ARGV variables to tease out command options, but have a few questions. Presently, when the argument '-help' is passed, the program displays my help documentation. How do I get the program to display the help documentation if there are no command line arguments? The code presently looks like...
sub help_doc_sr { print "blah blah blah...\n"; exit(0); } while ($count <= $#ARGV) { SWITCH: { $ARGV[$count] =~ m/(^-h$|^-help$)/ && do {help_doc_sr; last SWITCH;}; } $count++; } Another question is, since I am using things like -flag to find user supplied values, I want to create a graceful error message saying that a value isn't provided if the flag has been invoked. For instance... $perl sourse_code.pl -option value Should use 'value' against -option. If the user accidentally types... $perl source_code.pl -option I want the program to say something like "You forgot to give me a value when you invoked '-option'!" Currently, I am using something like $ARGV[$count+1] to see what comes after the flag. But in the simulated mistake above, $ARGV[$count+1] does not exist, so perl gives me errors...
|