I’m creating a perl script to convert a list of commands in a template file () and output them to another file in a different format in an output file ().
The commands in the template file will look as follows:
command1 --max-size=2M --type="some value"
I’m having some problems extracting the options and values from this string. So far i have:
m/(\s--\w*=)/ig
Which will return:
" --max-size="
" --type="
However I have no idea how to return both the option and value as a separate variable or how to accommodate for the use of quotes.
Could anyone steer me in the right direction?
side note: I’m aware that Getops does an awesome job at doing this from the command-line but unfortunately these commands are passed as strings 🙁
The code below produces
That is suitable to pass to
GetOptionsas follows:Finally, the code: