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

I don't know why it's a standard (the origins are probably somewhere deep in the past of Unix time) but the important thing is that it _is_ now a standard. People used to Unix commands will expect the usual method of dealing with command line options. Changing that is likely to confuse people unnecessarily.

Having said that, it's simple enough to change the behaviour of the Getopt::* modules. They all act on @ARGV so you just need to shift your filename off of the front of @ARGV before calling the option parsing function.

use Getopt::Std; my $file = shift; my %args; getopts 'abc', \%args; print "File is $file\n"; print "$_ is $args{$_}\n" for keys %args;
--
<http://dave.org.uk>

"The first rule of Perl club is you do not talk about Perl club."
-- Chip Salzenberg

  • Comment on Re: Why is it good practice for a cli script to take switch args before file list?
  • Download Code