Getopt::Long need a '-?' option 
Author Message
 Getopt::Long need a '-?' option

How do I put a "-?" option into a Getopt::Long?
This works:

require Getopt::Std;
Getopt::Std::getopts('h?b:c') or die "Usage: $0 [-?] [-h] [ -b xxx ]
[ -c ]";
print "Options:\n";
print "h:$opt_h.\n";
print "?:$opt_?.\n";
#I know "$opt_?" is weird but it does work!
####################
I can't get it working in the Long version:

use Getopt::Long;
&GetOptions( qw(
        help
        ?
        ));
print "Options:\n";
print "help:$opt_help.\n";
print "???:$opt_?\n"
################
I did get as much info as possible and looked through all of the perl
scripts but this type of thing is hard to find info on (yes I read the FAQ)
Thanks in Advance!
ANTISPAM: Change .kom to ".com"



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option

Quote:

> How do I put a "-?" option into a Getopt::Long?

You can only obtain this using an alias, and Getopt::Long of at least
version 2.13.

  use Getopt::Long;
  GetOptions ("help|?");    # -help and -? will both set $opt_help

-- Johan
   Author and maintainer of Getopt::Long



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option


Quote:

>> How do I put a "-?" option into a Getopt::Long?

>You can only obtain this using an alias, and Getopt::Long of at least
>version 2.13.

>  use Getopt::Long;
>  GetOptions ("help|?");    # -help and -? will both set $opt_help

>-- Johan
>   Author and maintainer of Getopt::Long

I usually do:
---------------8<----------
#!/usr/bin/perl -w

use strict;
use Getopt::Long;

sub usage ()
{
    print STDERR "usage: Your usage message\n";
    exit -1;
    } # usage

# Catch '-?', '-help' and '--help'

my $opt_n = 0;
Getopt::Long::Configure ("bundling");
GetOptions (
    "n:i" => \$opt_n,
    # More options ...
    ) or usage ();
--------------->8-------------
--
H.Merijn Brand
using perl5.005.03 on HP-UX 10.20, HP-UX 11.00, AIX 4.2.1, AIX 4.3.0, DEC
     OSF/1 4.0 and WinNT 4.0 SP-6a, often with Tk800.018 and/or DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option
GREAT!
But in this case, I want to output brief help with -? as in
$ program.pl -?
usage: program.pl [-machine] [-user] [-help] files
use -h for more help

when the user gives -h or -help they get more fully explained help output
$ program.pl -help
Usage: program.pl [-machine] [-user] [-help] files
Options:
-host           find current host
-user           search for current user
-help            this help screen

Anyway, I like the "alias" here and can use for other stuff

Thanks!

John.B


Quote:

> > How do I put a "-?" option into a Getopt::Long?

> You can only obtain this using an alias, and Getopt::Long of at least
> version 2.13.

>   use Getopt::Long;
>   GetOptions ("help|?");    # -help and -? will both set $opt_help

> -- Johan
>    Author and maintainer of Getopt::Long



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option
You perl guy's are GREAT!!!

This is my FIRST perl program and I want it to behave like a standard unix
program
This helps!

Thanks!
John



Quote:



> >> How do I put a "-?" option into a Getopt::Long?

> >You can only obtain this using an alias, and Getopt::Long of at least
> >version 2.13.

> >  use Getopt::Long;
> >  GetOptions ("help|?");    # -help and -? will both set $opt_help

> >-- Johan
> >   Author and maintainer of Getopt::Long

> I usually do:
> ---------------8<----------
> #!/usr/bin/perl -w

> use strict;
> use Getopt::Long;

> sub usage ()
> {
>     print STDERR "usage: Your usage message\n";
>     exit -1;
>     } # usage

> # Catch '-?', '-help' and '--help'
> # side effect, it also catches '---help', '----help' :-)

> my $opt_n = 0;
> Getopt::Long::Configure ("bundling");
> GetOptions (
>     "n:i" => \$opt_n,
>     # More options ...
>     ) or usage ();
> --------------->8-------------
> --
> H.Merijn Brand
> using perl5.005.03 on HP-UX 10.20, HP-UX 11.00, AIX 4.2.1, AIX 4.3.0, DEC
>      OSF/1 4.0 and WinNT 4.0 SP-6a, often with Tk800.018 and/or DBD-Unify
> ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
> Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option
How do I test if ANY arg is "-?" so I can output "brief usage" and exit
(the "-help" will be caught by GetOptions portion)
I don't care where in the arg string it is

John



Quote:



> >> How do I put a "-?" option into a Getopt::Long?

> >You can only obtain this using an alias, and Getopt::Long of at least
> >version 2.13.

> >  use Getopt::Long;
> >  GetOptions ("help|?");    # -help and -? will both set $opt_help

> >-- Johan
> >   Author and maintainer of Getopt::Long

> I usually do:
> ---------------8<----------
> #!/usr/bin/perl -w

> use strict;
> use Getopt::Long;

> sub usage ()
> {
>     print STDERR "usage: Your usage message\n";
>     exit -1;
>     } # usage

> # Catch '-?', '-help' and '--help'
> # side effect, it also catches '---help', '----help' :-)

> my $opt_n = 0;
> Getopt::Long::Configure ("bundling");
> GetOptions (
>     "n:i" => \$opt_n,
>     # More options ...
>     ) or usage ();
> --------------->8-------------
> --
> H.Merijn Brand
> using perl5.005.03 on HP-UX 10.20, HP-UX 11.00, AIX 4.2.1, AIX 4.3.0, DEC
>      OSF/1 4.0 and WinNT 4.0 SP-6a, often with Tk800.018 and/or DBD-Unify
> ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
> Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option
Quote:
> FYI: Most standard Unix programs don't accept '-?' as an option, but
> instead use -h, -H -help or --help. The reason for that is that the
> shell gets in the way when using a ?.

Right, sorry.
I do like a quick "-?" option to show brief usage and the -help to explain
the switches
I actually come from the Amiga CLI where it worked well (if I remember my
Amiga days correctly)

John



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option
[please, when following up to an article, respect the arrow of time,
and put your reply _after_ the (suitably trimmed) quoted text]

On Thu, 24 Feb 2000 17:31:59 -0700,

Quote:

> This is my FIRST perl program and I want it to behave like a standard unix
> program

[snip of enormous amount of unimportant quoted text]

FYI: Most standard Unix programs don't accept '-?' as an option, but
instead use -h, -H -help or --help. The reason for that is that the
shell gets in the way when using a ?.

# ls -?
/bin/ls: No match.
# ls -\?
/bin/ls: invalid option -- ?
Try `/bin/ls --help' for more information.

Using ? as the 'help' option character is DOS-ish, but not Unix-ish.

Martien
--
Martien Verbruggen              |
Interactive Media Division      | Begin at the beginning and go on till
Commercial Dynamics Pty. Ltd.   | you come to the end; then stop.
NSW, Australia                  |



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option


Quote:
>:

>FYI: Most standard Unix programs don't accept '-?' as an option, but
>instead use -h, -H -help or --help. The reason for that is that the
>shell gets in the way when using a ?.

Ever used Unix System 3? I'm now using UNIX like systems for about 15
years and saw the -h option appear first in GNU utils and perl. I
even changed perl4 to support -?

Quote:
># ls -?
>/bin/ls: No match.
># ls -\?
>/bin/ls: invalid option -- ?
>Try `/bin/ls --help' for more information.

>Using ? as the 'help' option character is DOS-ish, but not Unix-ish.

I do NOT agree! /? is DOSish, -? is unix-ish
Since most of my standard utils have been replace with GNU versions,
I got used to --help. You can turn of the 'No match' behaviour in
(t)csh with 'set nonomatch'

% pwd -?
No match.
% pwd -\?
usage: pwd
% set nonomatch
% pwd -?
usage: pwd
% pwd -h
usage: pwd
% pwd -help
usage: pwd
%

Quote:
>Martien

--
H.Merijn Brand
using perl5.005.03 on HP-UX 10.20, HP-UX 11.00, AIX 4.2.1, AIX 4.3.0, DEC
     OSF/1 4.0 and WinNT 4.0 SP-6a, often with Tk800.018 and/or DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)


Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option

Quote:

> GREAT!
> But in this case, I want to output brief help with -? as in
> $ program.pl -?
> usage: program.pl [-machine] [-user] [-help] files
> use -h for more help

> when the user gives -h or -help they get more fully explained help output
> $ program.pl -help
> Usage: program.pl [-machine] [-user] [-help] files
> Options:
> -host           find current host
> -user           search for current user
> -help            this help screen

Separate the options:

    GetOptions ("userwantsshorthelp|?", "help", ...);

    if ( defined $opt_userwantsshorthelp ) {
      ...
    }
    if ( defined $opt_help ) {
      ...
    }
    ... and so on ...


certain options. For example, the following cases will fool you:

    -outputfile -?   (provided -outputfile takes a string argument)
    -- -?

-- Johan
   Author and maintainer of Getopt::Long



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option


... snip ...

Quote:

>certain options. For example, the following cases will fool you:

>    -outputfile -?   (provided -outputfile takes a string argument)
>    -- -?

As you might have noticed, my test starts with


which tests if the quest for help is the only argument. This allows
to give brief help/usage if '-?' or '-help' is the only argument, while
allowing to perform specific help if placed in other context.

# myprog init -?

might give specific help (dealt with by GetOptions) for the specific
init task of myprog.

--
H.Merijn Brand
using perl5.005.03 on HP-UX 10.20, HP-UX 11.00, AIX 4.2.1, AIX 4.3.0, DEC
     OSF/1 4.0 and WinNT 4.0 SP-6a, often with Tk800.018 and/or DBD-Unify
ftp://ftp.funet.fi/pub/languages/perl/CPAN/authors/id/H/HM/HMBRAND/
Member of Amsterdam Perl Mongers (http://www.amsterdam.pm.org/)



Wed, 18 Jun 1902 08:00:00 GMT  
 Getopt::Long need a '-?' option
Geez! do I feel stupid!
I wrote a foreach loop:

which caught any question mark
I will change as you stated!
Thanks!
John


Quote:

> > GREAT!
> > But in this case, I want to output brief help with -? as in
> > $ program.pl -?
> > usage: program.pl [-machine] [-user] [-help] files
> > use -h for more help

> > when the user gives -h or -help they get more fully explained help
output
> > $ program.pl -help
> > Usage: program.pl [-machine] [-user] [-help] files
> > Options:
> > -host           find current host
> > -user           search for current user
> > -help            this help screen

> Separate the options:

>     GetOptions ("userwantsshorthelp|?", "help", ...);

>     if ( defined $opt_userwantsshorthelp )
>       ...
>     }
>     if ( defined $opt_help ) {
>       ...
>     }
>     ... and so on ...


> certain options. For example, the following cases will fool you:

>     -outputfile -?   (provided -outputfile takes a string argument)
>     -- -?

> -- Johan
>    Author and maintainer of Getopt::Long



Wed, 18 Jun 1902 08:00:00 GMT  
 
 [ 12 post ] 

 Relevant Pages 

1. Getopt::Long, using '?' as option

2. Getopt:Long arguments that are not (options or option values)

3. Getopt::mixed, and setting options for it's ise

4. Problem checking if a command line option has been specified using Getopt::Long

5. ANNOUNCE: Getopt::Long 2.9 -- Universal command line options processing

6. ANNOUNCE: Getopt::Long 2.6 -- Universal command line options processing

7. Using Getopt::Long with multiple options in quotes

8. Getopt::Long and Options in single quotes?

9. GetOpt::Long - Corequisite options?

10. ANNOUNCE: Getopt::Long 2.9 -- Universal command line options processing

11. ANNOUNCE: Getopt::Long 2.6 -- Universal command line options processing

12. Tk-Options-0.10: Interface to Getopt::Long and Tk

 

 
Powered by phpBB® Forum Software