on Thu, 20 Jun 2002 12:41:34 GMT, Martin A. Hansen wrote:
> i will elaborate the question:
>
>
> i have a huge script with many global variables and subroutines.
>
> several variable names are reused, but lexically scoped to
> subroutines and everything works fine.
>
> but if you forget (bugs do occur!) to declare a variable inside a
> subroutine it will get the global variable value and there _may not_
> be any error upon compilation! however, the program will crash or
> malfunction later on.
>
> what is the smart way to deal with this?
If I understand you correctly, you don't want your my-variables available
in your subroutines, but only in your main program. Just put a block
around the main code:
#! perl -w
use strict;
{
my $var = 'abc';
somesub();
}
sub somesub {
print $var;
}
This gives you (the wanted) error message:
Global symbol "$var" requires explicit package name at ...
(You could even make this block a sub itself and call it 'main' ;-)
--
felix
--
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]