#!/your/perl/here use strict; use warnings; use Getopt::Declare; my $option_spec = qq{ # note: required tab between last argument and description -x [ ] -x takes 1 or 4 args [required] -y [ ] -y takes 1 or 3 args [required] -z [] -z takes 1 or 2 args [required] At least one of these options is required, and all are mutually exclusive. [mutex: -x -y -z] Examples: $0 -x zero one two three $0 -y zero alpha beta $0 -z zero last_but_not_least }; my $options = Getopt::Declare->new( $option_spec ) or die "\n**** Error processing command line options, terminating $0\n"; sub do_something { print "@_\n"; } if ( $options->{'-x'} ) { if ( defined( $options->{'-x'}{''} ) ) { do_something("-x", $options->{'-x'}{''}, $options->{'-x'}{''}, $options->{'-x'}{''}, $options->{'-x'}{''} ) if $options->{'-x'} } else { do_something("-x", $options->{'-x'}{''} ); } } if ( $options->{'-y'} ) { if ( defined( $options->{'-y'}{''} ) ) { do_something("-y", $options->{'-y'}{''}, $options->{'-y'}{''}, $options->{'-y'}{''} ) if $options->{'-y'} } else { do_something("-y", $options->{'-y'}{''} ); } } if ( $options->{'-z'} ) { if ( defined( $options->{'-z'}{''} ) ) { do_something("-z", $options->{'-z'}{''}, $options->{'-z'}{''} ) if $options->{'-z'} } else { do_something("-z", $options->{'-z'}{''} ); } } #### C:\Perl\perl\perlmonks>469375.pl -y zero -y zero C:\Perl\perl\perlmonks>469375.pl -y zero one two -y zero one two C:\Perl\perl\perlmonks>469375.pl -z zero one -z zero one C:\Perl\perl\perlmonks>469375.pl -x zero -x zero C:\Perl\perl\perlmonks>469375.pl -x zero one two three -x zero one two three C:\Perl\perl\perlmonks>469375.pl -y zero -y zero C:\Perl\perl\perlmonks>469375.pl -y zero alpha beta -y zero alpha beta C:\Perl\perl\perlmonks>469375.pl -z zero -z zero C:\Perl\perl\perlmonks>469375.pl -z zero last_but_not_least -z zero last_but_not_least C:\Perl\perl\perlmonks>469375.pl -x zero -y zero -z zero Error: parameter '-y' not allowed with parameter '-x' Error: parameter '-z' not allowed with parameter '-x' (try 'C:\Perl\perl\perlmonks\469375.pl -help' for more information) **** Error processing command line options, terminating C:\Perl\perl\perlmonks\469375.pl