Re: how to set constants from command line?
It's not really a constant he wants, but a value that's read-only to everything but the setting routine. Some sort of object, perhaps?
Re: how to set constants from command line?
On Sun, Dec 15, 2013 at 11:28:02AM -0500, Parrot Raiser wrote: : It's not really a constant he wants, but a value that's read-only to : everything but the setting routine. Some sort of object, perhaps? Any parameter to sub MAIN is readonly by default, since parameters in general are readonly by default. Larry
how to set constants from command line?
I would like to set a series of magic numbers from the command line. I have in a program constant N-SCENARIOS = 10; which works great. But I would like to set an option in the command line, such as perl6 program.p6 scenarios=15 and then within program have the option assigned to the constant. I tried this with a BEGIN block, something like BEGIN { if @*ARGS[0] ~~ / scenarios \= (.d+) / { constant N-SCENARIOS = $0 } } say N-SCENARIOS; But this does not work. I could have a normal scalar my $scenarios ; But that doesn't seem as elegant as creating a constant. Any neat trick I am missing? Richard
Re: how to set constants from command line?
Hi Richard, On 12/12/2013 08:56 AM, Richard Hainsworth wrote: I would like to set a series of magic numbers from the command line. I have in a program constant N-SCENARIOS = 10; which works great. But I would like to set an option in the command line, such as perl6 program.p6 scenarios=15 .. then it's not a constant. So don't use a constant. Use a variable instead. I could have a normal scalar my $scenarios ; But that doesn't seem as elegant as creating a constant. Using a constant for something that isn't a constant doesn't strike me as elegant at all. Note that in Perl 6, there is no guarantee that command line arguments are known at compile time, so mucking with @*ARGS in BEGIN seems like a very bad idea. Cheers, Moritz