On Nov 8, Arul, Rex said: >use strict; >my $a = 2; >print "a val is $a\n"; >my $a = 10; >print "a val is $a\n"; > >My question is. How can I put a 'seat-belt' as to tag this kind of >inadvertent behavior as unacceptable? > >When I use, 'use warnings' pragma, it warns me. Is there anything that >would probably raise a compile/run-time error and fail at redeclarations >of variables in Perl?
Sure. From 'perldiag', we see that the warning raised belongs to the 'misc' category, so we simply write: use warnings FATAL => 'misc'; Now when you get the "my" variable $a masks earlier... message, your program will die. If that is too broad (you don't want ALL miscellaneous errors causing your program to die) you can get more specific with a custom warning handler: use warnings; BEGIN { $SIG{__WARN__} = sub { die $_[0] if $_[0] =~ /^"my" variable \S+ masks earlier declaration/; warn $_[0]; } } Now the specific warning you want will become fatal. -- Jeff "japhy" Pinyan [EMAIL PROTECTED] http://www.pobox.com/~japhy/ RPI Acacia brother #734 http://www.perlmonks.org/ http://www.cpan.org/ ** Look for "Regular Expressions in Perl" published by Manning, in 2002 ** -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]