in reply to odd things with my and our
Your output isprint "lib $my\n$our endlib";
As for the global vars across files, you should use use vars to declare the variable instead of our. In your test, the our declaration binds $lib::our only for the library.pm file (more specifically, it binds it only for the lexical scope of that our). Using use vars is not only more portable for older perls that don't support our, but it is truly global. And I don't understand at all trying to use my to achieve this, as it doesn't use the symbol table (ie, $lib::var vars).
Update: I was a little off here.. As jdtoronto points out below, you can still declare our variables to be global across files. our makes it so you can call a package variable by its short name ($foo) within the lexical scope. Outside that scope you can still get to it by its fully-qualified name ($lib::foo) as you do in your main code. But anyway, using use vars will make this work with older perls like you need, and get rid of your "deprecated" warnings.
package lib; use vars '$usevars'; $usevars = "foo"; ## now $lib::usevars is visible, even from other files
There's a lot of good reference material in the Functions, Subroutines, and Variables section of Tutorials about these three different types of variable declarations.
Update: added use vars snippet.
blokhead
|
|---|