Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

hi monks,
the problem is i need to give --verify as the command line option which is long and has a argument. And -x which is a single character option which also has a argument with it inside a perl program i would like to know how do i do this.....ie, it has to be something like this $ perl ex.pl --verify filename.txt -x name

please send in ur answers to syedtoah@yahoo.com or sibmail@indiatimes.com

  • Comment on how to use --xxx as a option using getopts

Replies are listed 'Best First'.
Re: how to use --xxx as a option using getopts
by japhy (Canon) on Aug 19, 2004 at 15:30 UTC
    I'm going to reply here because you asked here.

    This sounds like a job for Getopt::Long. Something very simple like:

    use Getopt::Long; my %opts; GetOptions( "verify=s" => \$opts{verify}, "x" => \$opts{x}, );
    See the documentation for more information; it's rather self-explanatory (and thorough).
    _____________________________________________________
    Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
    How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart
Re: how to use --xxx as a option using getopts
by beernuts (Pilgrim) on Aug 19, 2004 at 15:36 UTC
    Update: I see I've been beaten to the punch. ++ Japhy.

    Sorry to sound curmudgeonly, but this is answered in the perldoc for Getopt::Long. It's even mentioned (bundling) in the "Description" section in the first paragraph of the docs. I'll leave `perldoc Getopt::Long' as an exercise to the reader.

    In general, posting and then asking for responses to be sent to an email address is bad form. The idea of the community is to learn from one another. Which I'm sure you'll agree doesn't happen if the answer goes off into the ether.