develooper Front page | perl.perl6.users | Postings from September 2017

rw optional parameters

Thread Next
Norman Gaywood
September 16, 2017 11:32
rw optional parameters
Message ID:
I have this:
use v6;
sub MAIN( :$debug = False, :$verbose = False  ) {
    $verbose = True if $debug;
    say "verbose={$verbose}, debug={$debug}";
$ ./tt.p6
verbose=False, debug=False
$ ./tt.p6 --verbose
verbose=True, debug=False
$ ./tt.p6 --debug
Cannot assign to a readonly variable ($verbose) or a value
  in sub MAIN at ./tt.p6 line 6
  in block <unit> at ./tt.p6 line 4

So $verbose is read-only. I think the compiler could have told me this a
compile time?

I try to fix it:
sub MAIN( :$debug = False, :$verbose is rw = False  ) {
$ ./tt.p6 --debug
===SORRY!=== Error while compiling /home/ngaywood/./tt.p6
Cannot use 'is rw' on optional parameter '$verbose'.
at /home/ngaywood/./tt.p6:4

Not sure what the neat way of doing this is.

Norman Gaywood, Computer Systems Officer
School of Science and Technology
University of New England
Armidale NSW 2351, Australia
Phone: +61 (0)2 6773 2412  Mobile: +61 (0)4 7862 0062

Please avoid sending me Word or Power Point attachments.

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About