Qukz has asked for the wisdom of the Perl Monks concerning the following question:
Hello.
I'm trying to use an option with an optional value and then test whether the option was used and if so whether an optional value was used with it; here's what I have:
use strict; use warnings; my $foo = undef; GetOptions( 'foo:s' => \$foo, ); my $sn = $ARGV[0]; if ($foo and $foo ne undef) { print "foo option used with optional value: $foo \n"; } elsif ($foo) { print "foo option used with no optional value \n"; } else { print "foo option not used at all \n"; }
That doesn't work, but hopefully it better illustrates what I'm trying to do.
Any help would be greatly appreciated.
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: Options with optional values and condititions
by kennethk (Abbot) on Oct 02, 2012 at 16:14 UTC | |
|
Re: Options with optional values and condititions
by runrig (Abbot) on Oct 02, 2012 at 16:23 UTC | |
by Anonymous Monk on Oct 02, 2012 at 18:47 UTC | |
by runrig (Abbot) on Oct 02, 2012 at 18:50 UTC | |
|
Re: Options with optional values and condititions
by Neighbour (Friar) on Oct 03, 2012 at 13:29 UTC |