Update: I noticed that I hadn't read the OP closely enough. I've reworked it to provide optional parameters. The exact specification is lacking in the OP, so this is my best guess (to date):

Then there's Getopt::Declare:

#!/your/perl/here use strict; use warnings; use Getopt::Declare; my $option_spec = qq{ # note: required tab between last argument and description -x <x0> [<x1> <x2> <x3>] -x takes 1 or 4 args [required] -y <y0> [<y1> <y2>] -y takes 1 or 3 args [required] -z <z0> [<z1>] -z takes 1 or 2 args [required] At least one of these options is required, and all are mutually ex +clusive. [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'}{'<x1>'} ) ) { do_something("-x", $options->{'-x'}{'<x0>'}, $options->{'-x'}{'<x1>'}, $options->{'-x'}{'<x2>'}, $options->{'-x'}{'<x3>'} ) if $options->{'- +x'} } else { do_something("-x", $options->{'-x'}{'<x0>'} ); } } if ( $options->{'-y'} ) { if ( defined( $options->{'-y'}{'<y1>'} ) ) { do_something("-y", $options->{'-y'}{'<y0>'}, $options->{'-y'}{'<y1>'}, $options->{'-y'}{'<y2>'} ) if $options->{'- +y'} } else { do_something("-y", $options->{'-y'}{'<y0>'} ); } } if ( $options->{'-z'} ) { if ( defined( $options->{'-z'}{'<z1>'} ) ) { do_something("-z", $options->{'-z'}{'<z0>'}, $options->{'-z'}{'<z1>'} ) if $options->{'- +z'} } else { do_something("-z", $options->{'-z'}{'<z0>'} ); } }
Which gives these results:
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\p +erlmonks\469375.pl

-QM
--
Quantum Mechanics: The dreams stuff is made of


In reply to Re: -x accepts up to 3 additional arguments by QM
in thread -x accepts up to 3 additional arguments by tcf03

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.