Why does perl not warn when redeclaring a variable in an inner scope? -


as bit of perl novice, ran bug accidentally did (example simplified):

my $i=0;  for(my $i=0;$i<10; $i++)   {     print $i;   } print $i; # $i zero, code expected 9 

from why don't warning when redeclare perl foreach control variable? understand behavior expected; should not warning unless re-declaration in same scope.

however, can not understand why case. why perl not issue warning here? seems me cause of errors, , not intended. there common case normal programming style, warning annoying?

perl doesn't tend warn style issues, find hard believe intentionally want have same var name @ different scope depths.

the case might useful comes mind is

{     $x = $x;     ... changes $x ... } # $x restored here. 

on plus side, there perlcritic rule identify such problem.


Comments

Popular posts from this blog

linux - Does gcc have any options to add version info in ELF binary file? -

android - send complex objects as post php java -

charts - What graph/dashboard product is facebook using in Dashboard: PUE & WUE -