Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Enforce order 1

Status
Not open for further replies.

blarneyme

MIS
Jun 22, 2009
160
US
Using getopts and have 4 options; H, M, X , C
getopts('HX:M:C');
use vars qw($opt_H, $opt_X, $opt_M, $opt_C);
if ($opt_H) {...};
if ($opt_C) {...};
if ($opt_M) {...};
if ($opt_X) {...};

1. H is for help
2. C, M or X can be used by themselves
3. C and M can be used together and C must be used first
4. C cannot be used with X

How can I enforce the requirements for 3 & 4?
 
if ($opt_M && $opt_C) {
die "Can't use options M & C at the same time!\n";
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Of course. I should have recognized that.

For number 3, how would I make sure C is before M?
 
Just make sure you process them in that order, always process your C part first, and if you have M the process it.

if your really worried you can do a bunch of ifs like

if (opt_c && opt_M) {
&process_c
&process_m
}
elsif (opt_c) {
&process_c
}
elsif (opt_M) {
&process_M
}



~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[noevil]
Travis - Those who say it cannot be done are usually interrupted by someone else doing it; Give the wrong symptoms, get the wrong solutions;
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top