in reply to GetOpts not working:
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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: GetOpts not working:
by finfan (Acolyte) on Dec 08, 2015 at 18:36 UTC |