0

I am having some problems with getopts in perl.

I use:

getopts("abc:ds:", \%options);

and I'm cheking the options with

if (defined $options{a})

where $options is the hash the options are written into.

After the options the user has to enter a file name, that I locate with $ARGV[0]. The problem is, that the user can not put the options after the file name, but only before.

So this is working:

skript.pl -a file.txt

And this is not working:

skript.pl file.txt -a

How can I escape this problem?

Thank you!

-Alex

toolic
  • 57,801
  • 17
  • 75
  • 117
Darius
  • 135
  • 3
  • 13

1 Answers1

4

Getopt::Std is really too limited to use in almost every case.

Use Getopt::Long and set the permute option to allow this.

ysth
  • 96,171
  • 6
  • 121
  • 214