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

Re: checking MAIN arguments

Thread Previous | Thread Next
Luca Ferrari
April 12, 2022 08:23
Re: checking MAIN arguments
Message ID:
On Tue, Apr 12, 2022 at 10:15 AM Luca Ferrari <> 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.IO.d // warn "Specify the
directory [$dir]" } ) {
    say $dir;

The only thing that I find in the documentation at
<> 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

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


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