in reply to Re: getopt?
in thread getopt?

thanks, I _really_ misread something there.
I'm using scalar(keys %args) instead of $args, now.
Is there anyway to use both getopts and GetOptions so that you can code for either GetOpt::Long or GetOpt::Std ?

Replies are listed 'Best First'.
Re: Re: Re: getopt?
by tommyw (Hermit) on Oct 25, 2001 at 03:30 UTC

    Brute force and ignorance suggests:

    @ARGV2=@ARGV; GetOptions(...); @ARGV=@ARGV2; getopts(...);
    But note that GetOptions allows you to abbreviate the commands as long as their uniquely identifiable. So you can pass --f instead of --file, and therefore don't necessarily need getopts, provided you're willing to live with the double hyphen.

    PS. I still don't understand the lest for the size of %args as an alternative to testing $help. If you supply 2 single hyphen parameters (possibly including -h) then you don't get the help message?

      Actually, you don't even need to live with the double hyphen. Single hyphen is also parsed by Getopt::Long. Note that clustering does not work, however: -rex gets interpreted as one option, 'rex' (Update: (thanks chipmunk!) unless you turn them on). But otherwise you can use single-letter options as long as they are distinct. If you really want to do this sort of option-parsing, though, try Getopt::Mixed.
        Getopt::Long does support bundling of single-letter options, e.g. -rex for -r -e -x. This feature is just not enabled by default. You can turn it on with: Getopt::Long::Configure('bundling'); Getopt::Long has quite a few configuration options, all of which are explained in the documentation.
      Yes, you're right. I realized that last night and fixed it.
      now, it reads...
      if ($help || !($file && $database && $user && $password)){ print "rip_sched -h/--help -f/--file datafile -d/--database database - +u/--user database-user -p/--password database-password\n"; exit 0; }