in reply to How to use getopt and $#argv together?

I noticed that after using "getopt" at the start of the code reduces $#argv to "0"

It doesn't for me.

$ perl -MGetopt::Std -E'getopt(\%opts); say 1+$#ARGV;' -- -f a b c d 3 $ perl -MGetopt::Std -E'say Getopt::Std->VERSION' 1.06

I suspect that you misstated your problem, asking about the number of arguments or options when you meant to ask how to check what options were specified. We could be of better assistance if you told us what you are actually trying to do.

Replies are listed 'Best First'.
Re^2: How to use getopt and $#argv together?
by TomDLux (Vicar) on Mar 09, 2011 at 22:25 UTC

    That's because you pass in the opt variable, but don't define any options to search for.

    325$ perl -MGetopt::Std -E'getopt(\%opts); say "@ARGV";' -- -f a -d b +-r -v a -d b -r -v 326$ perl -MGetopt::Std -E'getopt("fdrv",\%opts); say "@ARGV";' -- -f +a -d b > 327$

    As Occam said: Entia non sunt multiplicanda praeter necessitatem.

      No, specifying the options doesn't change anything.

      $ perl -MGetopt::Std -E' getopt("fdrv",\%opts); say 1+$#ARGV; say "@ARGV"; ' -- -f a b c d 3 b c d

      The only thing you showed is that removing the arguments produces an empty @ARGV.