viffer has asked for the wisdom of the Perl Monks concerning the following question:
I'm converting a shell script to perl. The shell script has a number of switches passed to it, one being "-?".
Using "getopts" I can cater for all the various switches *except* the -?.
I can't use a variable '$opt_?' as it gives a syntax error.
I tried to list the various switches then use $ARGV[0}to pick up the -? if it was supplied, but having the '-', in front of the question mark, makes getopts look for a switch, rather than treating it as $ARGV[0}.
Is there any way I can pass "-?" as an option for getopts?
I'm calling the script via
Removing the dash preceding the question mark in the command isn't an option, neither is using something other than "-?".script.pl -d -P MBKL107 -v name=fred -?
my $opt_z; our ( $opt_d,$opt_h,$opt_l,$opt_L,$opt_i,$opt_o,$opt_P,$opt_p,$opt_q,$ +opt_r,$opt_v,$opt_c ); $Getopt::Std::STANDARD_HELP_VERSION = 1; getopts('dhlLio:P:pqrv:c'); if ($ARGV[0]eq "-?") { $opt_z = $ARGV[0]; }
If I knew the "-?" would always be first I could put the check for -? in $ARGV[0} before the getops command, but I don't know what order the switches will be provided in so that's not an option either.
Also I don't have control over the command line so can't use a double dash on the command line to let the script know the options are finished and that -? is now $ARGV[0}
Any help your collective wisdom can offer up will be greatly appreciated.
Thanks Kev
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: getopts and -?
by Anonymous Monk on May 10, 2011 at 01:19 UTC | |
by viffer (Beadle) on May 10, 2011 at 02:35 UTC | |
by Anonymous Monk on May 10, 2011 at 02:52 UTC | |
by viffer (Beadle) on May 10, 2011 at 02:57 UTC | |
by viffer (Beadle) on May 10, 2011 at 02:43 UTC | |
by viffer (Beadle) on May 10, 2011 at 02:49 UTC | |
by viffer (Beadle) on May 10, 2011 at 02:54 UTC | |
Re: getopts and -?
by ikegami (Patriarch) on May 10, 2011 at 01:33 UTC | |
Re: getopts and -?
by kejohm (Hermit) on May 10, 2011 at 01:20 UTC | |
by viffer (Beadle) on May 10, 2011 at 01:47 UTC | |
by kejohm (Hermit) on May 10, 2011 at 02:28 UTC | |
by JavaFan (Canon) on May 10, 2011 at 11:12 UTC | |
by Anonymous Monk on May 10, 2011 at 02:26 UTC |