12

Perl 6 has great builtin command-line parsing via MAIN. However, I faced a problem which seems to be trivial, but I cannot figure it out.

A simple MAIN:

sub MAIN(Int :n(:$num)) {
    say "You passed: " ~ $num;
}

Then I can call my script as:

$ ./test.p6 -n=1

or:

$ ./test.p6 --num=1

But can't with:

$ ./test.p6 -n 1  # or even -n1

or:

$ ./test.p6 --num 1

I went through the design document for MAIN with no luck. How can I make this work?

Pat
  • 36,282
  • 18
  • 72
  • 87
cuonglm
  • 2,766
  • 1
  • 22
  • 33

1 Answers1

9

2023 update This was resolved in 2021. See @librasteve's comment.

[I've deleted all of the rest of this answer except info that might still be still salient for readers with other issues with command line options.]

For your convenience, here are the other two extant bug reports I found for MAIN: Usage does not print required type for positional params in MAIN and fail to handle numbers as option name for MAIN.

Maybe use an options module such as Getopt::Long?

raiph
  • 31,607
  • 3
  • 62
  • 111