in reply to Re^8: My globals are visable; but undef'ed
in thread My globals are visable; but undef'ed

Because if I have to type a variable name in two different files, my typo rate is fairly high. Therefore I really, really want to declare it in one file, and let strict.pm catch my typos everywhere else.
But putting use vars($var) does not make any difference from putting our $var; at the top of the file for this, or as far as I know any other use. In other words, I just use our as a direct replacement for vars. And if you do, there really isn't any difference (except that vars has more awkward scope).

And I don't use attributes on global variables (I do use them on global subroutines, though).

update: or are you really adding to the same package from different files as much as that? I really do that once or twice a year.

Replies are listed 'Best First'.
Re^10: My globals are visable; but undef'ed
by tilly (Archbishop) on Jul 31, 2008 at 22:55 UTC
    Yes, it does make a difference. If I have use vars qw($var); in one library, and I use that library in my script, then $var is declared in my script as well. Which means that if I get to my script and think it should be $vars, that thinko is caught by strict.pm.

    If I was using our instead then that mistake would never be caught because I would have declared it differently in the library and the script.

        If you Export the variables, then you don't need to declare them at all in your script. :-)

        I grant that it is fairly rare that you need to have 2 different files with code in the same package. But it does happen from time to time. For example you might encounter that at a first pass in refactoring some spaghetti. For another example some modules may need to autogenerate code in another package's namespace. In those situations it is better to use vars than to declare with our.