print "lib $my\n$our endlib";
Your output is unbuffered, and since there's no \n at the end of this line, it gets caught in the STDOUT buffer until the program exits. In the meanwhile, warn prints its thing to STDERR (whose buffer gets flushed after each warning because of the newlines). Put a newline at the end of this print (or unbuffer STDOUT with $|=1) and you'll get output you expect.

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


In reply to Re: odd things with my and our by blokhead
in thread odd things with my and our by jcpunk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.