in reply to Re: Passing Options
in thread Passing Options

check Getopt::Long!
I just did. I cannot find anywhere how to tell Getopt::Long to parse the command line as wished.
GetOptions( 't=s' => \ our $target, 'b=s' => \ our $buildtype, 'r=s' => \ @releases );
That requires multiple -t, -b and -r arguments. From a command line of
-r foo bar baz -b dog cat -t pony
it will put foo in @releases, dog in $buildtype, pony in $target, and leave the rest in @ARGV.
use Getopt::Long; our @releases; GetOptions( 't=s' => \ our $target, 'b=s' => \ our $buildtype, 'r=s' => \ @releases ); print "Target: $target\n"; print "Buildtype: $buildtype\n"; print "Releases: @releases\n"; print "ARGV: @ARGV\n"; __END__ Target: pony Buildtype: dog Releases: foo ARGV: bar baz cat
Not at all as wished.

I don't know any module that will parse the command line as was wished, but it shouldn't be too hard to roll your own.

Abigail

Replies are listed 'Best First'.
Re: Re: Passing Options
by fruiture (Curate) on Aug 12, 2002 at 15:33 UTC

    Probably the "originally wanted" was only abstract: "Pass more than one value for a commandline option". Why should anybody write a new module that parses the options in a way that differs from nearly all other applications, if he could just change the own program's usage message and make it work with standard modules and methods?

    --
    http://fruiture.de
      Perhaps, but why make such broad suggestions if the example is pretty clear? At least have the decency to write in your reply that your suggestion is violating the given example. Give the readers a hint that you actually thought about the question and answer and that you didn't just try to get a answer - any anwer - just to say something.

      I don't know why anyone whould write a new module, and I don't know what that has to do with the answer. But now we are getting something like:

      • Poster: "How do I do X"? Here's an example.
      • Reply: Use Y!
      • Me: Y doesn't solve X, here look, it does Z.
      • You: Yeah, but perhaps the poster wanted to do Z.
      I'd think this forum would quickly become useless if all threads go this way.

      If you have a solution that doesn't solve the problem, but solves a different one, say so. Don't suggest it solves the problem. That only wastes a lot of time of people.

      (As for wanting options to take multiple arguments, without having to repeat the option, I think that's reasonable. I've wanted that in the past as well. The fact that there's a module to parse options in a different way doesn't invalidate the wish to do it otherwise. This is Perl remember, not Python).

      Abigail

        I think i see the point and you're right, but i still think that the Poster's X does not directly specify that he doesn't want Z and probably he wants Z because Z is already implemented in Y, common and solves X, although it doesn't perfectly do what the Poster wanted, maybe because he didn't know about Z. In the end, (s)he will find out :)

        --
        http://fruiture.de