Hello,

   I am not able to understand the following behaviour of perl
Getopt::Long. Here is the snippet of code that I am not able to
understand:

Start of code
-------------------------------------------------
#!/usr/local/bin/perl
use Getopt::Long;

my $filename;
print "Before : ARGV = @ARGV\n";
$ret = GetOptions('abc=s' =>\$filename);
print "Return value = $ret  ";
print "filename = $filename\n";
print "After : ARGV = @ARGV\n";
-------------------------------------------------

How I expect this code to behave is to match the command line switch
-abc. But it is matching all the swithces -a , -ab , and -abc. Can
someone help me in understanding this. When I ran this program the
following are the results:

1. Command Line Invocation:  Getopt_Example_9.pl -a path
Output from the above code:
Before : ARGV = -a path
Return value = 1  filename = path
After : ARGV =

2. Command Line Invocation:  Getopt_Example_9.pl -ab path
Output from the above code:
Before : ARGV = -ab path
Return value = 1  filename = path
After : ARGV =

3. Command Line Invocation:  Getopt_Example_9.pl -abc path
Output from the above code:
Before : ARGV = -abc path
Return value = 1  filename = path
After : ARGV =

4. Command Line Invocation:  Getopt_Example_9.pl -ac path
Before : ARGV = -ac path
Unknown option: ac
Return value =   filename =
After : ARGV = path


For Your Information:
----------------------
perl -V on my machine gives:
--------------------------------------------------------------------------

Summary of my perl5 (revision 5.0 version 6 subversion 0) configuration:

  Platform:
    osname=solaris, osvers=2.6, archname=sun4-solaris
    uname='sunos linsparc89 5.6 generic_105181-21 sun4u sparc
sunw,ultra-5_10 '
    config_args=''
    hint=recommended, useposix=true, d_sigaction=define
    usethreads=undef use5005threads=undef useithreads=undef
usemultiplicity=undef
    useperlio=undef d_sfio=undef uselargefiles=define
    use64bitint=undef use64bitall=undef uselongdouble=undef
usesocks=undef
  Compiler:
    cc='gcc', optimize='-O', gccversion=2.95 19990728 (release)
    cppflags='-fno-strict-aliasing -I/usr/local/include
-I/opt/local/include'
    ccflags ='-fno-strict-aliasing -I/usr/local/include
-I/opt/local/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64'
    stdchar='unsigned char', d_stdstdio=define, usevfork=false
    intsize=4, longsize=4, ptrsize=4, doublesize=8
    d_longlong=define, longlongsize=8, d_longdbl=define, longdblsize=16
    ivtype='long', ivsize=4, nvtype='double', nvsize=8, Off_t='off_t',
lseeksize=8
    alignbytes=8, usemymalloc=y, prototype=define
  Linker and Libraries:
    ld='gcc -shared', ldflags =' -L/usr/local/lib '
    libpth=/usr/local/lib /lib /usr/lib
    libs=-lsocket -lnsl -lgdbm -ldb -ldl -lm -lc -lcrypt -lsec
    libc=/lib/libc.so, so=so, useshrplib=false, libperl=libperl.a
  Dynamic Linking:
    dlsrc=dl_dlopen.xs, dlext=so, d_dlsymun=undef, ccdlflags=' -Wl,-E'
    cccdlflags='-fPIC', lddlflags='-W,l-E -G -L/usr/local/lib
-R/usr/local/lib'


Characteristics of this binary (from libperl):
  Compile-time options: USE_LARGE_FILES
  Built under solaris
  Compiled at Dec 14 2000 17:41:50
  @INC:
    /usr/local/lib/perl5/5.6.0/sun4-solaris
    /usr/local/lib/perl5/5.6.0
    /usr/local/lib/perl5/site_perl/5.6.0/sun4-solaris
    /usr/local/lib/perl5/site_perl/5.6.0
    /usr/local/lib/perl5/site_perl

--------------------------------------------------------------------------------------------

Thanks and Regards,
D.Rajanikanth

Reply via email to