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

Re: checking MAIN arguments

Thread Previous | Thread Next
From:
Luca Ferrari
Date:
April 12, 2022 08:23
Subject:
Re: checking MAIN arguments
Message ID:
CAKoxK+4WQ8SFZkR3r-poT2rHzBHbF++4+NRmtZZmYwzvJ9wwbA@mail.gmail.com
On Tue, Apr 12, 2022 at 10:15 AM Luca Ferrari <fluca1978@gmail.com> wrote:
>
> Hello all,
> given this simple program:
>
> sub MAIN( Str :$dir where { .so && .IO.d // warn "Specify the
> directory [$dir]" } ) {
>     say $dir;
> }
>

Shame on me: it works if I omit the topic and substitute it with the
explicit variable, thus:

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

The only thing that I find in the documentation at
<https://docs.raku.org/type/Signature#index-entry-where_clause> is:
"The code in where clauses has some limitations: anything that
produces side-effects (e.g., printing output, pulling from an
iterator, or increasing a state variable) is not supported and may
produce surprising results if used. Also, the code of the where clause
may run more than once for a single typecheck in some
implementations."

Is there a better approach to spurting warning messages when a
parameter is not correct (without dealing with USAGE() and friends)?

Thanks,
Luca

Thread Previous | 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