Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^2: A short whishlist of Perl5 improvements leaping to Perl7 (used only once)

by LanX (Cardinal)
on Nov 27, 2020 at 18:30 UTC ( #11124297=note: print w/replies, xml ) Need Help??


in reply to Re: A short whishlist of Perl5 improvements leaping to Perl7
in thread A short whishlist of Perl5 improvements leaping to Perl7

> Not really, it lets perl catch typos, for example if you have $the_variable_I_want_to_check = 0; somewhere in your code and then $the_varaible_I_want_to_check = 1; later, using strict and my will raise an error at compile time. Python would just silently allow it.

should be mentioned that Perl has an "used only once" warning, I'm surprised that python doesn't.

> Also having automine would mean that using perl 5 code that wasn't written with strict would compile, but turn package variable into lexicals.

automine or whatever we'd call it must obviously be a pragma extending strict, not a default feature. New pragmas breaking old code is no surprise.

update

looks like used-only-once gets deactivated with explicit declaration

#use strict; use warnings; my $the_variable_I_want_to_check = 0; # somewhere in your code and then $the_varaible_I_want_to_check = 1;

C:/Perl_524/bin\perl.exe -w d:/tmp/pm/t_typo.pl Name "main::the_varaible_I_want_to_check" used only once: possible typ +o at d:/tmp/pm/t_typo.pl line 8.

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^3: A short whishlist of Perl5 improvements leaping to Perl7 (used only once)
by tobyink (Canon) on Nov 27, 2020 at 22:41 UTC

    "looks like used-only-once gets deactivated with explicit declaration"

    Lexical variables and variables beginning with an underscore never trigger that warning.

Re^3: A short whishlist of Perl5 improvements leaping to Perl7 (used only once)
by dsheroh (Monsignor) on Nov 28, 2020 at 12:50 UTC
    should be mentioned that Perl has an "used only once" warning
    True, but (in the context of this thread) even that would only save you from unique typos. Make the same typo twice and the typoed name is no longer "used only once".
      Sure, but there is always a risk assessment in life ...

      ... there is no vaccination against car accidents!

      On a side note: Repeated typos happen for me when I use auto-completion in my IDE. But if I already have an IDE I can run a linter on the fly warning me from names with close Levenshtein distance.

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://11124297]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (6)
As of 2021-01-17 00:02 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    Notices?