Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Perl6: how do I read mixed parameters from the command line?

Tags:

raku

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 -w xyz  -q def  -r abc 

How are they doing this? Is there some module for this?

like image 682
Todd Avatar asked Nov 30 '19 02:11

Todd


1 Answers

Here is an example using 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]
like image 76
Håkon Hægland Avatar answered Sep 19 '22 05:09

Håkon Hægland