Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
481 views
in Technique[技术] by (71.8m points)

raku - Perl6:如何从命令行读取混合参数?(Perl6: how do I read mixed parameters from the command line?)

I run programs all the time from the command line that allow your to mix the order of the parameters.

(我一直在命令行上运行程序,这些程序可让您混合参数的顺序。)

And they catch you if you throw something extra into the mix.

(如果您在混合中添加其他内容,它们会抓住您。)

For example:

(例如:)

$xxx -r abc -q def -w xyz

($ xxx -r abc -q def -w xyz)

$xxx -w xyz -q def -r abc

($ xxx -w xyz -q def -r abc)

How are they doing this?

(他们是如何做到的?)

Is there some module for this?

(是否有一些模块?)

Many thanks,

(非常感谢,)

-T

(-T)

  ask by Todd translate from so

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Here is an example using Getopt::Long :

(这是使用Getopt :: Long的示例:)

use v6;
use Getopt::Long;

my %opt = help => False, 'r=s' => "", 'q=s' => "", 'w=s' => "";
my %options = get-options(%opt).hash;
say %options;
say @*ARGS;

Example run:

(示例运行:)

$ p.p6  -w xyz -q def -r abc hello
{help => False, q => def, r => abc, w => xyz}
[hello]

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...