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 }

In reply to Re: The command line arguments by dasgar
in thread The command line arguments by abcdefg

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.