develooper Front page | perl.perl5.porters | Postings from May 2023

Make => on assignment a syntax error?

Thread Next
From:
Ovid
Date:
May 17, 2023 12:50
Subject:
Make => on assignment a syntax error?
Message ID:
CA+M4CHvxSnQqqTNj_8DnF4FKGa7fhpa+fcKCGOnEEVRR=ioCWQ@mail.gmail.com
Hi all,

Someone recently complained about trying to debug something like this[1]:

    $ perl -Mstrict -Mwarnings -E 'my $foo => 42; say $foo;'
    Useless use of a constant (42) in void context at -e line 1.
    Use of uninitialized value $foo in say at -e line 1.

If you're working with a codebase that doesn't have warnings, you won't
even get those warnings. You'll just get a silent, and very hard to track
down error.

When you're both declaring a variable and assigning to it, can we make
using => instead of = a syntax error? I've been bitten by this a few times
and the Useless use of a constant warning can get lost in a sea of stack
traces.

Best,
Ovid

1. https://github.polettix.it/ETOOBUSY/2023/05/16/syntax-checking/

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