Perl's global variables are only global in the package they are in.
Each variable type has a heirachical structure so a $main::varname is only a global in the package "main" and my $varname although stored in the "main" package is in it's own area for lexicals and they have precidence over "package globals".
so lexical $varname does not overwrite $main::varname
but "print $varname;" will only access lexical $varname.
so if you just use "$varname = value" (use strict) will moan that it doesn't know if the variable is a lexical $varname or a package global $varname and even what package $varname is meant to be in.
Even if the default package is main - you still have to tell it what package you are refering to - go figure, why have a default package but can't default to it (ok unless you use [ our $varname ]) but that falls appart if you inadvertantly create a lexical of the same name!.
However I now see that you can create another package "on the fly" just by defining the variable $glob::varname.
so if i want in effect to use application globals via a require file, i define a package for those variables and refer to them correctly by specifying the package name infront of the variable i want to use.
I would like someone to confirm that I have grasped variable storage so I can modify my scripts to all use (use strict).
But if i'm wrong I don't want to waste my time changing already bad code to just as bad code - that would we pointless.
Regards,
1DMF
Each variable type has a heirachical structure so a $main::varname is only a global in the package "main" and my $varname although stored in the "main" package is in it's own area for lexicals and they have precidence over "package globals".
so lexical $varname does not overwrite $main::varname
but "print $varname;" will only access lexical $varname.
so if you just use "$varname = value" (use strict) will moan that it doesn't know if the variable is a lexical $varname or a package global $varname and even what package $varname is meant to be in.
Even if the default package is main - you still have to tell it what package you are refering to - go figure, why have a default package but can't default to it (ok unless you use [ our $varname ]) but that falls appart if you inadvertantly create a lexical of the same name!.
However I now see that you can create another package "on the fly" just by defining the variable $glob::varname.
so if i want in effect to use application globals via a require file, i define a package for those variables and refer to them correctly by specifying the package name infront of the variable i want to use.
I would like someone to confirm that I have grasped variable storage so I can modify my scripts to all use (use strict).
But if i'm wrong I don't want to waste my time changing already bad code to just as bad code - that would we pointless.
Regards,
1DMF