Getopt works on @ARGV, so you can't use it to process function arguments. Well, not without doing @ARGV = @_ which might well break other stuff.
You can try something like this:
#!/usr/bin/perl use strict; use warnings; use Getopt::Std; use Data::Dumper; sub getopt_fun { my %args; { local @ARGV = @_; getopt 't', \%args; } print Dumper \%args; } getopt_fun (-t => 'foo');
Edit: narrowed the scope of the local.
In reply to Re^2: Using a 'getopt' in module code
by calin
in thread Using a 'getopt' in module code
by throop
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |