Scully4Ever has asked for the wisdom of the Perl Monks concerning the following question:

I wrote a script that uses Getopt::Long to get the command line arguments. Is there a way to allow the user to use “!=“ in addition to "=“ so the user could for example request data not equal to year 2016 or data equal to year 2016?

Replies are listed 'Best First'.
Re: Parsing NE Command Line Arguments
by ww (Archbishop) on Sep 28, 2016 at 15:26 UTC

    Have you checked what seem to be at least half a dozen possibilities found in the doc? Most require creating a handler, but that should be simple enough for your example case. Of course, if your example is not the real usage, the balance of this node is probably unhelpful.

    Also, see,

    pass_through (default: disabled)
    With pass_through anything that is unknown, ambiguous or supplied with an invalid option will not be flagged as an error. Instead the unknown option(s) will be passed to the catchall <> if present, otherwise through to @ARGV . This makes it possible to write wrapper scripts that process only part of the user supplied command line arguments, and pass the remaining options to some other program.

    That/s pretty far down in the doc; the others (left as an exercise for the SOPW) are found in earlier parts of http://perldoc.perl.org/Getopt/Long.html (but don't be misled by the earlier section on negation, which deals with negating built in options.

      The pass_through option will work. Thank you.

Re: Parsing NE Command Line Arguments
by Dallaylaen (Chaplain) on Sep 29, 2016 at 00:44 UTC

    I was in such situation several times, and mostly ended up adding negation (or other modifier) to the parameter itself, then post-processing it with regexp or something. I.e.

    use warnings; use strict; use Getopt::Long; my $foo; GetOptions( "foo=s" => \$foo, ); if ($foo) { print $foo =~ /!(.*)/ ? "All but $1" : "Only $foo"; };
    bash$ perl all-but-foo.pl --foo 4 Only 4 bash$ perl all-but-foo.pl --foo \!4 All but 4