jmf11 has asked for the wisdom of the Perl Monks concerning the following question:
I would like to pass a named argument with 3 (or more) values using Getopt::Long. To complicate things a bit, the 3 arguments include strings and operators (for an eval call) and I would like to use the argument multiple times. Here is an approach I've considered with a string with comma delimiter:
The complicating factor seems to be that I need to include the --list option many times so defining individual options for the 3 elements isn't practical. There is an example in the Perl 5 v16.2 documentation that looks promising (--coordinates 52.2 16.4 --rgbcolor 255 255 149) but there is a warning that it is experimental and there is no hint as to how to implement it.perl evaluateit.pl --list 'strA,==,100' --list 'strB,>,1000' #!/usr/bin/env perl use strict; use warnings; use Getopt::Long; my %opts = (); my $getoptsresult = GetOptions(\%opts,"list=s@"); my %h = (strA=>100,strB=>999); foreach(@{$opts{list}}){ my @args = split /\,/; my $code = join(' ',$h{$args[0]},$args[1],$args[2]); my $answer = eval($code); print "answer: $answer\n"; #do something with answer }
Any comments about passing multiple named arguments each with lists of values would be helpful.
|
---|
Replies are listed 'Best First'. | |
---|---|
Re: getopt long, named argument with multiple values
by dasgar (Priest) on Jan 07, 2013 at 04:21 UTC | |
by jmf11 (Initiate) on Jan 09, 2013 at 00:57 UTC | |
Re: getopt long, named argument with multiple values
by BrowserUk (Patriarch) on Jan 07, 2013 at 02:23 UTC |
Back to
Seekers of Perl Wisdom