in reply to Perl Variables storage location and scope question.
my $val (lexical scope), no warning message is shown. Nothing like "masking earlier declaration of $val".
You can get warnings like these with Perl::Critic. While some of the advice given by that module can be ignored if one knows what one is doing, for things like this (custom warnings) it can be quite useful. For example, running it on your code gives, among other things, "Reused variable name in lexical scope: $val at line 7, column 2. Invent unique variable names". You can promote this to a severe violation that is always reported by creating a .perlcriticrc file in your home directory that contains
[Variables::ProhibitReusedNames] severity = 5
And also use this file to customize other warnings, like quieting those that you don't need. Also, note you can use perlcritic --verbose 10 to get explanations of the warnings.
|
|---|