Beefy Boxes and Bandwidth Generously Provided by pair Networks
Problems? Is your data what you think it is?
 
PerlMonks  

Re: Why is it good practice for a cli script to take switch args before file list?

by Sidhekin (Priest)
on Jul 19, 2006 at 15:35 UTC ( [id://562320]=note: print w/replies, xml ) Need Help??


in reply to Why is it good practice for a cli script to take switch args before file list?

To (non-)answer your stated question first: I have no good answer for "why" beyond "it's the (POSIX) standard".

The gnu tools happily ignore this standard, so I have no qualms about doing the same.

Adressing your want: I don't think you can with Getopt::Std, but Getopt::Long can be configured to allow it, and I invariably do so. The configure option is called "permute", and is usually the default. It is also implied by the "gnu_getopt" option, which makes it behave like GNU getopt_long, and is what I normally use:

use Getopt::Long ':config', 'gnu_getopt'; # or, during runtime: # Getopt::Long::Configure('gnu_getop');

print "Just another Perl ${\(trickster and hacker)},"
The Sidhekin proves Sidhe did it!

Replies are listed 'Best First'.
Re^2: Why is it good practice for a cli script to take switch args before file list?
by leocharre (Priest) on Jul 19, 2006 at 16:59 UTC

    I can't see any POSIX on that... Where do you see that?

      I can't see any POSIX on that... Where do you see that?

      Thanks for that convenient link.

      The arguments following the last options and option-arguments are named "operands".

      (Emphasis mine.)

      Also on that page, under the heading "Utility Syntax Guidelines":

      Guideline 9:
      All options should precede operands on the command line.

      "Should" and "guidelines" may not be the strongest of words, but the intent seems clear enough for me.

      print "Just another Perl ${\(trickster and hacker)},"
      The Sidhekin proves Sidhe did it!

        Thank you so much for your help- for finding where that was. After reading the discussion here I have no doubts that the best thing to do is expect options before operands.

        The slight preference of listing paths before options would not be worth the confusion and added bugs at all.

        POSIX ( SUS?, i guess we'll be calling it at some point.. ) has some *must* haves, and *should* haves to qualify for a true POSIX os/app/lib/whatever. I think this case is clearly not a *must* have.. But then, wiping yourself after you #2 is also not a *must* do.
        So.. options before operands it is.

        And I like what merlyn said, makes a ton of sense. I once saw somewhere that a good utility is liberal in what it accepts as input and conservative in what it outputs.. And how people should be more like that. Sigh.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://562320]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others wandering the Monastery: (5)
As of 2024-04-25 14:36 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found