Beyond the assignment to $opt{input}, your requirement seems to be for the normal operaton of Getopt::Long.
Consider this code:
#!/usr/bin/env perl use 5.010; use strict; use warnings; use Getopt::Long; my %opt; GetOptions(\%opt, 'v'); say 'Before assigning $opt{input}:'; if ($opt{v}) { say $ARGV[0], ' (verbose)'; } else { say $ARGV[0], ' (quiet)'; } $opt{input} = $ARGV[0]; say 'After assigning $opt{input}:'; if ($opt{v}) { say $opt{input}, ' (verbose)'; } else { say $opt{input}, ' (quiet)'; }
Using your two command line examples, this produces:
$ pm_getopt_arg.pl ex-post-facto Before assigning $opt{input}: ex-post-facto (quiet) After assigning $opt{input}: ex-post-facto (quiet)
$ pm_getopt_arg.pl -v ex-post-facto Before assigning $opt{input}: ex-post-facto (verbose) After assigning $opt{input}: ex-post-facto (verbose)
-- Ken
In reply to Re^3: non-option argument question
by kcott
in thread non-option argument question
by dr_jkl
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |