Hi all

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

script.pl -d -P MBKL107 -v name=fred -?
Removing the dash preceding the question mark in the command isn't an option, neither is using something other than "-?".

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


In reply to getopts and -? by viffer

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.