You've got two issues... first, getopts() requires you to specify a reference to a hash, not a hash directly (change %opts to \%opts in the getopts() call). Second, you're trying to assign $opts{f} to $file, but you're comparing with eq instead. Change eq to =. Here's the full code with fixes:
use Getopt::Std; # declare the perl command line flags/options we want to allow my %opts; getopts('f:', \%opts); # test for the existence of the options on the command line. if ($opts{f}) { my $file = $opts{f}; print "$file\n"; }
In reply to Re: GetOpts not working:
by stevieb
in thread GetOpts not working:
by finfan
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |