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