Anonymous Monk has asked for the wisdom of the Perl Monks concerning the following question:

And from a golf field again. I like to omit parentheses with built-ins, but:

>perl -Mstrict -Mautodie -wE "my $s='.'; opendir my $h, $s # ok" >perl -Mstrict -Mautodie -wE "my $s='.'; opendir(my $h, $s); # ok" >perl -Mstrict -Mautodie -wE "my $s='.'; opendir my ($h), $s; # ok" >perl -Mstrict -Mautodie -wE "my $s='.'; opendir my $h, $s; # not ok" Parentheses missing around "my" list at -e line 1. >perl -Mstrict -Mautodie -wE "my $s='.'; opendir my $h, $s or bang(); +# ok" >perl -Mstrict -Mautodie -wE "my $s='.'; (opendir my $h, $s); # ok"

(Don't care if bang doesn't exist because of autodie in this case). A bug?

Replies are listed 'Best First'.
Re: Semicolon terminating paren-less call to 'opendir' triggers a bogus warning
by LanX (Saint) on Sep 07, 2023 at 23:06 UTC
    The warning isn't bogus, because you could have meant my ($h, $s)

    But it's only warning, which is not really relevant for golfing and disabled easily.

    Cheers Rolf
    (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
    Wikisyntax for the Monastery

      Why doesn't the first example give the same warning? The only difference that I see is the semicolon.
      Bill
        You are right, it's only the semicolon.

        The parser is full of heuristics trying to DWIM ambiguities.

        So probably that's one of the side effects, when the code ends abruptly. 🤷‍♂️

        Cheers Rolf
        (addicted to the 𐍀𐌴𐍂𐌻 Programming Language :)
        Wikisyntax for the Monastery