c has asked for the wisdom of the Perl Monks concerning the following question:

I just found the pearl of:
use Getopt::Std;
and I am using it effectively within my code, however I am having some issues trying to find the best way to have the script echo a help menu when no flags are specified. Currently, I am using:
getopts("n:f:hc",\%option); if (!$option{n} && !$option{f}) { help(); exit; } sub help { print<<EOF Usage: dnsmod [ -h ] [ -n ] [ -f ] -n <domain> -f <corp || client > -h print this help page EOF }
This works, however as I add more flag options to my script, this could become very tedious and could cause problems if someone other than myself plans to add some flags of their own. Is it possible to use $#ARGV or some other built in to measure whether or not flags were specified such that my test loop would not have to be updated with every new feature stuck in future revisions of the code?

humbly -c

Replies are listed 'Best First'.
Re: Looking for an easier way
by rchiav (Deacon) on Jul 18, 2001 at 20:48 UTC
    how about..
    help() unless keys %option;
    Rich
      %option will be empty if there were no options supplied, so you can change that to just:
      help() unless %option;
      Thanks, I'm very new if not dripping wet behind the ears when it comes to hashes. I am familiar with "keys". I'll look into it.

      Again, thanks. -c