I am writing a executable script(perl) that takes arguments from the command line. Here is some different syntaxs, I can think of:
myPerlScript 10 42myPerlScript myarg1=10 myarg2=42myPerlScript -myarg1=10 -myarg2=42myPerlScript myarg1 10 myarg2 42myPerlScript -myarg1 10 -myarg2 42
I do not like option 1. as it is not possible to give the arguments in arbitrary order, or skip the arguments to rely on default values. I would also like to give 2(or 3,…) dimensional arguments. Here are some examples again:
myPerlScript myarg 10x20myPerlScript myarg=10x20myPerlScript -myarg 10x20myPerlScript -myarg=10x20myPerlScript -myarg=10 20myPerlScript -myarg=10,20
What is the recommended syntax? or what would you recommend? and does it depend on situations and/or what the script is used for?
I don’t know much about perl, but in ruby world (and the rest of unix that I can observe) this seems to be the most accepted idiom:
There’s a difference between single and double dash. Some commands have two forms: long (full command name) and short (a single letter, for brevity). Double dash is for long form, single – for short one. Real life example:
I’d say that using single dash with long form will surprise people. Don’t do that 🙂
And I also can recommend this excellent book: Building awesome command-line applications in Ruby. Although it will be of less value to you, because it’s in ruby, not perl.