The patch below does not include tests or documentation, which I will
happily add if there is approval for the idea.
Before:
% perl -we 'my @ARGV'
%
After:
% ./perl -we 'my @ARGV'
Variable @ARGV will occlude global variable of that name at -e line 1.
It's just a warning:
% ./perl -e 'my @ARGV'
%
--- op.c.orig 2008-11-14 18:09:35.000000000 -0800
+++ op.c 2008-11-14 18:21:53.000000000 -0800
@@ -397,6 +397,18 @@
/* check for duplicate declaration */
pad_check_dup(name, is_our, (PL_curstash ? PL_curstash : PL_defstash));
+ /* same name as common global? */
+ if (!is_our && ckWARN(WARN_MISC)) {
+ if (strEQ(name, "@ARGV") || strEQ(name, "$ARGV") ||
+ strEQ(name, "@INC") || strEQ(name, "%INC") ||
+ strEQ(name, "%ENV") || strEQ(name, "%SIG") ||
+ strEQ(name, "@ISA")) {
+ Perl_warner(aTHX_ packWARN(WARN_MISC),
+ "Variable %s will occlude global variable of that name",
+ name);
+ }
+ }
+
if (PL_parser->in_my_stash && *name != '$') {
yyerror(Perl_form(aTHX_
"Can't declare class for non-scalar %s in \"%s\"",
--
Peter Scott
http://www.perlmedic.com/
http://www.perldebugged.com/
Thread Next