Hey guys!
I would like to create a script which gets input from the user via the flags. I use the GetOpt module for that. It looks like:
./my_script <action> --option1 --option2 ...
Example:
./my_script create --folder empty --size 50 ...
The action is not part of the GetOpt flags so I get it as $ARGV[0].
I would like to add a new flag that gets a string which can contain other flags (or any other string in that matter), something like this:
./my_script create --folder empty --size 50 --additional hey how ---are --you 555
So I can insert it into a variable:
$var = "hey how ---are --you 555"
I did some research and found out that I can use the pass_through flag of GetOpt. Problem is that I can't use the module Getopt::Long::Configure("pass_through") so I'm stuck with Getopt::Long.
Also, I found out that I can use '--' option. But it really feels to me as a workaround and I don't want to make the users use it.
Furthermore, I can play with @ARGV array by removing the action and the additional information and then using the GetOpt, something like this:
1. insert the action into a variable and remove it from the @ARGV
2. insert the additional information into a variable and remove it from the @ARGV
3. Use GetOpt on the new @ARGV.
But it does not feel so right.
Are there any other methods? (I asked a similar question on another forum but there weren't any other answers).
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.