Well, here is my slightly altered version, I just put your library.pm in the same directory as the script BUT note I added the package name:
#!/usr/bin/perl -w use strict; use library; print "Library-my: ", $library::my, "\n"; print "Library-our: ", $library::our, "\n"; my $thing = $library::my; my $other = $library::our; print "Thing: $thing\nOther: $other";
and the package:
package library; my $my = "my"; our $our = "our"; print "lib $my\n$our endlib \n\n";
now the result is:
Use of uninitialized value in print at testing.pl line 5. lib my our endlib Library-my: Library-our: our Thing: Other: our Use of uninitialized value in concatenation (.) or string at testing.pl line 11.
Which is exactly as I would expect. The our declaration is added to the symbol table, but the my is lexically scoped within the package and thus invisible outside it. As for our being deprecated, well, perldoc for 5.8.0 does not say so. Using our effectively globalises the variable, which is generally considered poor coding style, at least the way I was taught!

Wouldn't it be cleaner to be able to get the value programatically without the effects, possibly quite dangerous, of a global? This works and allows you to get the varaibles from within the package without the global.

#!/usr/bin/perl -w use strict; use library; my ($lib_my, $lib_our) = library->retvals; print "Returned my : $lib_my and returned our : $lib_our\n"; #------------------------- #library.pm package library; my $my = "my"; our $our = "our"; sub retvals { $self = shift; return $my, $our; }
jdtoronto

In reply to Re: odd things with my and our by jdtoronto
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.