I'm not sure what you "tried", but I think you're approaching the issue the wrong way.
The way that I would approach the problem would be to use Getopt::Std or Getopt::Long to read in the options first. Then write code to handle the validation of the options. That's where you'll handle the "or" situation.
The example code below illustrates what I'm suggesting. You'll probably want to add more validation and error trapping, but it will show how to handle the "or" logic of options that you're wanting to do.
use strict;
use warnings;
use Getopt::Long;
my $prod_type = "";
my $in_file = "";
my $out_file = "";
my $img_file = "";
my $valid = GetOptions(
'p=s' => \$prod_type,
'i=s' => \$in_file,
'o=s' => \$out_file,
'h=s' => \$img_file,
);
if (($in_file eq "") and ($img_file eq "")) {
my $msg = "";
die "Missing required option(s). The -i or -h option must be specifi
+ed.";
}
if ($in_file ne "") {
# do some stuff and ignore the -h flag
}
else {
# do other stuff
# earlier if statement guarantees that -h flag was used
# i.e there was no -i flag used, but the -h flag was used
}
|