go ahead... be a heretic | |
PerlMonks |
Re: join thisby btrott (Parson) |
on May 26, 2001 at 07:39 UTC ( [id://83467]=note: print w/replies, xml ) | Need Help?? |
I don't think you're specifying the problem well enough. The
line you give as an example of an argument list:
will *not* necessarily be parsed into a list like the one you posted. It is *entirely* up to the program who is receiving these arguments how to parse them, and what to do with them. As an example, you are implying that the "--out" option should be followed by a string argument (this is implied by the fact that in your list, you have the line "--out out.txt". But how can you possibly know that, given an arbitrary set of options? "--out" could simply be a boolean flag, not taking any additional arguments, and "out.txt" could be a file supplied as an argument to the program that you're running. The point is, your post suggest no way of discerning this information, and w/o that, there's really no way we can help you parse the config options. And in fact, although I don't know what your script is trying to do, I would strongly discourage you from trying to parse the command line options to another program--unless you *are* that other program, you have no way of knowing what the options mean, and what arguments they take, etc. Now, if you *do* know that information, then you can use Getopt::Long to parse the arguments, kind of like this: This gives: But just as a demonstration of what I was saying above, if we change that GetOptions spec to this: we now get this: Which just goes to show you that unless you know what, for example, "--out" means, you're really out of luck.
In Section
Seekers of Perl Wisdom
|
|