In Unix, programs usually take switch arguments first and other arguments later. That's still the case in real unices like FreeBSD, and also in SunOS. However, GNU has changed this behaiviour to accept options anywhere before the first lone double dash argument. They haven't only made this change in their utility programs but that's also the default behaiviour of the getopt function in the GNU C library (the behaiviour can be overridden by the caller but of course normal programs don't do this). This change causes some incompatibilities, as an argument starting with a minus after an argument not starting with a minus is parsed differently. In this respect, the change is much more obtrusive then long options using double hyphens, as that syntax was otherwise an error. Luckily, as they know this change is incompatible, GNU also gave us an escape route: just define the POSIXLY_CORRECT environment variable to true, and programs will go back to the traditional unix behaiviour. Note also that these incompatibilities rarely cause trouble in practice, because when you don't know if the arguments expand to something starting with a minus, you have to escape them with a double minus anyway, and that escapes all the argumets. (If you ask for my opinion, I find the new behaiviour sometimes convenient but only rarely, so I think it might not be worth what it costs. However, I used linux in my entire life and *BSD only briefly, so I'm quite biased. Also note that it would cause too much breakage in scripts to change the new behaiviour now, so it will probably stay in GNU libc.)

Now as for perl programs. I've never used the Getopt::Std module, but I used Getopt::Long which can be configured to whatever option style you want the program to have. I uses the following incanatation to make the option parsing GNU-like.

Getopt::Long::Configure "bundling", "gnu_compat", "prefix_pattern=(--| +-)";

In reply to Re: Why is it good practice for a cli script to take switch args before file list? by ambrus
in thread Why is it good practice for a cli script to take switch args before file list? by leocharre

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.