Reputation: 37136
Is there a way to get Perl to avoid treating negative values as command-line switches? Neither stringifying nor backslashing the argument seems to help under 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).
Upvotes: 6
Views: 1978
Reputation: 104065
$ perl -E "say join ', ', @ARGV" -- -1 2 3
-1, 2, 3
The trick is using the double-hyphen (--
) to end the option parsing. Double-hyphen is a GNU convention:
$ touch -a
usage: touch [-acfm] [-r file] [-t [[CC]YY]MMDDhhmm[.SS]] file ...
$ touch -- -a
$ ls
-a
Upvotes: 14