How can I get Perl to accept negative numbers as command line arguments?

Is there a way to get Perl to avoid handling negative values ​​as command line switches? It seems that neither the string nor the inverse of the argument helps on Linux:

$ perl  -e 'print "@ARGV\n";' 4 5
  4 5

$ perl  -e 'print "@ARGV\n";' -4 5
  Unrecognized switch: -4  (-h will show valid options).

$ perl -e 'print "@ARGV\n";' "-4" 5
  Unrecognized switch: -4  (-h will show valid options).

$ perl -e 'print "@ARGV\n";' '-4' 5
  Unrecognized switch: -4  (-h will show valid options).

$ perl -e 'print "@ARGV\n";' \-4 5
  Unrecognized switch: -4  (-h will show valid options).
+5
source share
1 answer
$ perl -E "say join ', ', @ARGV" -- -1 2 3
-1, 2, 3

The trick uses a double hyphen ( --) to complete the parameter parsing. Double-hyphen is the GNU convention :

$ touch -a
usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
$ touch -- -a
$ ls
-a
+13
source

All Articles