Maybe a set of options like --eq field_1,value_1 --gt field_2,value2 --lt field_3,value_3 and so on? Using this sort of "Polish notation" (operator followed by operands) wouldn't be too hard for users to grok.
And having two operands be comma separated within the single arg string is not a problem, either. Something like this might be suitable:
#!/usr/bin/perl use strict; use Getopt::Long; my $Usage = <<ENDUSE; Usage: $0 [--operator operand1,operand2] ... operators: --gt --lt --eq operand1: field_id operand2: value ENDUSE my %opts; ( GetOptions( \%opts, 'gt=s@', 'lt=s@', 'eq=s@' ) and keys %opts ) or die $Usage; my @conditions; for my $opt ( sort keys %opts ) { for my $arg ( @{$opts{$opt}} ) { if ( $arg =~ /^([^,]+),([^,]+)$/ ) { push @conditions, "$1 $opt $2"; } else { die "Bad option values at '--$opt $arg'\n\n$Usage"; } } } print join "\n", "The stated conditions for this run are:", @condition +s, "";
That will print the usage synopsis if run with no args or if run with unusable args (like "-?" or "--help" or whatever). It will also check, for each option, whether the supplied arg string contains two things separated by a comma. More checks would be easy to add -- whatever you think is appropriate.
In reply to Re: Command Line Argument Processing
by graff
in thread Command Line Argument Processing
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |