Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

getops() Problems #666

Closed
p5pRT opened this issue Sep 30, 1999 · 3 comments
Closed

getops() Problems #666

p5pRT opened this issue Sep 30, 1999 · 3 comments

Comments

@p5pRT
Copy link

p5pRT commented Sep 30, 1999

Migrated from rt.perl.org#1546 (status was 'resolved')

Searchable as RT1546$

@p5pRT
Copy link
Author

p5pRT commented Sep 30, 1999

From brent@marooned.tamu.edu

Created by brent@marooned.tamu.edu

If I use​:
$ret = getopts('hf​:d​:m​:');
then
if (!$ret || $opt_h){
  &PrintUsage;
  exit(1);
}

$ret has the value of "1" even when no args are entered.
I do not understand why this is so. Can functionality be added
that will make getopts() return 0 if no args are passed?

The manpage also could use some work.
perldoc Getopt​::Std

It appears to me that​:
getopt('oDI'); # -o, -D & -I take arg.
appears to be incorrect...I understood that : signified if it took an arg or not.

Also, can I ask that the manpage explain the return codes?

Perl Info


Site configuration information for perl 5.00401:

Configured by root at Thu Sep 11 18:55:58 CDT 1997.

Summary of my perl5 (5.0 patchlevel 4 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.0.27, archname=i686-linux
    uname='linux marooned 2.0.27 #6 thu apr 10 10:45:30 cdt 1997 i686 '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=n useperlio=define d_sfio=
  Compiler:
    cc='gcc', optimize='-O2', gccversion=2.7.2.1
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=4, usemymalloc=n, randbits=31
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /shlib /lib /usr/lib
    libs=-lgdbm -ldbm -ldb -ldl -lm -lc
    libc=/lib/libc.so.5.4.17, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'



@INC for perl 5.00401:
	/usr/lib/perl5/i686-linux/5.00401
	/usr/lib/perl5
	/usr/lib/perl5/site_perl/i686-linux
	/usr/lib/perl5/site_perl
	.


Environment for perl 5.00401:
    HOME=/home/brent
    LANG (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/brent:/home/brent/bin:.:/home/brent/bin:/sbin:/usr/sbin:/usr/ucb:/bin:/usr/bin:/usr/etc:/usr/bin/X11:/usr/games:/usr/local/bin:.
    PERL_BADLANG (unset)
    SHELL=/bin/zsh


Site configuration information for perl 5.00401:

Configured by root at Thu Sep 11 18:55:58 CDT 1997.

Summary of my perl5 (5.0 patchlevel 4 subversion 1) configuration:
  Platform:
    osname=linux, osvers=2.0.27, archname=i686-linux
    uname='linux marooned 2.0.27 #6 thu apr 10 10:45:30 cdt 1997 i686 '
    hint=recommended, useposix=true, d_sigaction=define
    bincompat3=n useperlio=define d_sfio=
  Compiler:
    cc='gcc', optimize='-O2', gccversion=2.7.2.1
    cppflags='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    ccflags ='-Dbool=char -DHAS_BOOL -I/usr/local/include'
    stdchar='char', d_stdstdio=define, usevfork=false
    voidflags=15, castflags=0, d_casti32=define, d_castneg=define
    intsize=4, alignbytes=4, usemymalloc=n, randbits=31
  Linker and Libraries:
    ld='gcc', ldflags =' -L/usr/local/lib'
    libpth=/usr/local/lib /shlib /lib /usr/lib
    libs=-lgdbm -ldbm -ldb -ldl -lm -lc
    libc=/lib/libc.so.5.4.17, so=so
    useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=, ccdlflags='-rdynamic'
    cccdlflags='-fpic', lddlflags='-shared -L/usr/local/lib'



@INC for perl 5.00401:
	/usr/lib/perl5/i686-linux/5.00401
	/usr/lib/perl5
	/usr/lib/perl5/site_perl/i686-linux
	/usr/lib/perl5/site_perl
	.


Environment for perl 5.00401:
    HOME=/home/brent
    LANG (unset)
    LD_LIBRARY_PATH (unset)
    LOGDIR (unset)
    PATH=/home/brent:/home/brent/bin:.:/home/brent/bin:/sbin:/usr/sbin:/usr/ucb:/bin:/usr/bin:/usr/etc:/usr/bin/X11:/usr/games:/usr/local/bin:.
    PERL_BADLANG (unset)
    SHELL=/bin/zsh

@p5pRT
Copy link
Author

p5pRT commented Oct 1, 1999

From [Unknown Contact. See original ticket]

<brent@​marooned.tamu.edu> writes​:

The manpage also could use some work.
perldoc Getopt​::Std

It appears to me that​:
getopt('oDI'); # -o, -D & -I take arg.
appears to be incorrect...I understood that : signified if it took an arg or not.

That is the difference between 'getopt' (documented as above) and 'getopts'
which is documented (on the next line but one) to use the '​:'.

--
Nick Ing-Simmons <nik@​tiuk.ti.com>
Via, but not speaking for​: Texas Instruments Ltd.

@p5pRT
Copy link
Author

p5pRT commented Oct 1, 1999

From @tamias

On Fri, Oct 01, 1999 at 12​:26​:00AM -0500, brent@​marooned.tamu.edu wrote​:

If I use​:
$ret = getopts('hf​:d​:m​:');
then
if (!$ret || $opt_h){
&PrintUsage;
exit(1);
}

$ret has the value of "1" even when no args are entered.
I do not understand why this is so. Can functionality be added
that will make getopts() return 0 if no args are passed?

getopts() returns 1 if parsing of options was successful, and '' if there
were any errors. This is just like many of Perl's builtin functions, such
as open() which return true for success and false for failure.

If you want to know whether any args are passed, then you should test the
value of scalar(@​ARGV).

Ronald

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

1 participant