in reply to Getopt::Long return value
I have the "Programming with perl-Modules" from Patwardhan and Irving (year 1997) where this information is not present...
now this gives ok results *most* of the cases, but if you have commandline parameters separatedly, GetOpt silently ignores them:#!/usr/bin/perl -w use strict; use Getopt::Long; # If it comes to parallelizing, How many processes do we allow to star +t # default is amount of CPUs on that system. May be overridden by comma +ndline my $cpu = &num_cpus; my $goback = GetOptions('cpu=i', \$cpu, 'c=i', \$cpu, 'help', \&cmdline_usage, 'h', \&cmdline_usage); print "Number of CPUs here: $cpu\n"; print "Goback was: $goback\n"; # {{{ get the number of CPUs on that system # returns: number of CPUs or 1 if no /proc/cpuinfo was found sub num_cpus { my $num_cpus = 0; my $infofile = '/proc/cpuinfo'; if($^O eq 'linux') { # Yes this is Linux we're running on if(-e $infofile) { # and cpuinfo exists open FILE, $infofile; while(<FILE>) { $num_cpus++ if(/processor/); } close FILE; } } # elsif ... your favourite OS detection routine here # If this is not a known OS we're running on ($num_cpus is then 0) # so better be careful and assume 1 CPU return $num_cpus || 1; } # }}}
rj@proxima:~ > pxp.pl -cpu 1 Number of CPUs here: 1 Goback was: 1 => Ok rj@proxima:~ > pxp.pl -cpu Option cpu requires an argument Number of CPUs here: 2 Goback was: => Ok rj@proxima:~ > pxp.pl -cpu 1 -h=1 Option h does not take an argument Number of CPUs here: 1 Goback was: => Ok rj@proxima:~ > pxp.pl -cpu 1 -h 1 Usage: -c, --cpu set the number of CPUs (define parallelization) -h, --help print this usage information Number of CPUs here: 1 Goback was: 1 => IMHO not OkCiao
Update: The last case definitedly is not ok according to 1211. Iīm citing:
If the option specifier is ``one:i'' (i.e. takes an optional integer argument), then the
following situations are handled:
-one -two -> $opt_one = '', -two is next option
-one -2 -> $opt_one = -2
Now that means it WOULD have been ok if I declared h as h:i, but I
havenīt.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Re: Getopt::Long return value
by bikeNomad (Priest) on Jun 26, 2001 at 00:40 UTC | |
by PetaMem (Priest) on Jun 26, 2001 at 01:30 UTC | |
|
Re: Re: Getopt::Long return value
by Anonymous Monk on Jun 26, 2001 at 01:25 UTC | |
|
Re: Re: Getopt::Long return value
by bikeNomad (Priest) on Jun 26, 2001 at 06:48 UTC | |
by PetaMem (Priest) on Jun 26, 2001 at 10:48 UTC |