in reply to odd things with my and our
and the package:#!/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";
now the result is:package library; my $my = "my"; our $our = "our"; print "lib $my\n$our endlib \n\n";
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!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.
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.
jdtoronto#!/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; }
|
|---|