develooper Front page | perl.perl6.users | Postings from April 2022

checking MAIN arguments

Thread Next
From:
Luca Ferrari
Date:
April 12, 2022 08:16
Subject:
checking MAIN arguments
Message ID:
CAKoxK+7vArxkOoAaBMOPV0OLei9jHpvydXbP4Ks=r4tqtaDCyA@mail.gmail.com
Hello all,
given this simple program:

sub MAIN( Str :$dir where { .so && .IO.d // warn "Specify the
directory [$dir]" } ) {
    say $dir;
}

it works as I expect on ancient versions of rakudo, e.g., 202-01, but
it fails miserably on current rakudo:

% raku ~/tmp/test.p6 --dir=foo
Use of uninitialized value of type Any in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to
something meaningful.
 in block  at /home/luca/tmp/test.p6 line 4
Specify the directory []
 in block  at /home/luca/tmp/test.p6 line 4
Specify the directory [foo]
 in block  at /home/luca/tmp/test.p6 line 4
Use of uninitialized value of type Any in string context.
Methods .^name, .raku, .gist, or .say can be used to stringify it to
something meaningful.
 in block  at /home/luca/tmp/test.p6 line 4
Specify the directory []
 in block  at /home/luca/tmp/test.p6 line 4
Usage:
 /home/luca/tmp/test.p6 [--dir=<Str where { ... }>]

Note that in the above output there is a point, in the middle, where
the wanr function has the value of the argument, so I don't understand
why it is complaining.
Is there a way to spurt a warn message in the case a parameter is not fine?

Thanks,
Luca

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About