in reply to Re^2: non-option argument question
in thread non-option argument question

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

Replies are listed 'Best First'.
Re^4: non-option argument question
by dr_jkl (Acolyte) on Sep 12, 2012 at 19:41 UTC
    I suppose this is what I get for trying to write perl at 2am. Thank you very much!