[32985] in Perl-Users-Digest
Perl-Users Digest, Issue: 4261 Volume: 11
daemon@ATHENA.MIT.EDU (Perl-Users Digest)
Fri Aug 8 03:09:16 2014
Date: Fri, 8 Aug 2014 00:09:03 -0700 (PDT)
From: Perl-Users Digest <Perl-Users-Request@ruby.OCE.ORST.EDU>
To: Perl-Users@ruby.OCE.ORST.EDU (Perl-Users Digest)
Perl-Users Digest Fri, 8 Aug 2014 Volume: 11 Number: 4261
Today's topics:
Declaring and using global variables (Tim McDaniel)
Digest Administrivia (Last modified: 6 Apr 01) (Perl-Users-Digest Admin)
----------------------------------------------------------------------
Date: Fri, 8 Aug 2014 06:32:02 +0000 (UTC)
From: tmcd@panix.com (Tim McDaniel)
Subject: Declaring and using global variables
Message-Id: <ls1qt2$nit$1@reader1.panix.com>
It's a bit late and I'm a bit tired, I've never used "our" and rarely
used "use vars", and I want to have the best style.
At the $ORKPLACE, we do "use strict;" and "use warnings;". We usually
don't use global variables, but it occasionally happens. While
restructuring the code to use accessor functions may be a more
virtuous action, I can't restructure the code -- I'd just like to
clean up a few things from the output of Perl::Critic. Our Perl
environment is well past 5.6.
We sometimes refer to dynamic variables in the same file and sometimes
in other files. Some package Adventure::Cave may use "use vars
qw(...)" to "declare" dynamic variables for that package, and other
packages "use Adventure::Cave;" and then refer to variables as
"$Adventure::cave::whatever". We don't do exporting or importing.
That is, if you want a more concrete (contrived) example,
package Adventure::Cave;
use strict;
use warnings;
use vars qw(
$lamp
$food
$water
);
$lamp = 1;
$food = 2;
$water = 3;
...
sub whatnot {
...
if ($object == $lamp) { ... }
...
}
...
and in another file
package Player;
use strict;
use warnings;
use Adventure::Cave;
...
sub whatever {
...
if ($thingy == $Adventure::Cave::lamp) { ... }
...
}
...
Can I and should I just replace
use vars qw($lamp $food $water);
with
our ($lamp, $food, $water);
? We don't have more than one package in a file and we do "use vars"
only at top level, so I think the difference in scoping between the
two should not matter.
Other than "use Adventure::Cave;", should I be doing something in
Player before referring to $Adventure::Cave::lamp?
Perl::Critic::Policy::Variables::ProhibitPackageVars complains, but I
don't like to do "## no critic" if there's a right way to avoid it.
--
Tim McDaniel, tmcd@panix.com
------------------------------
Date: 6 Apr 2001 21:33:47 GMT (Last modified)
From: Perl-Users-Request@ruby.oce.orst.edu (Perl-Users-Digest Admin)
Subject: Digest Administrivia (Last modified: 6 Apr 01)
Message-Id: <null>
Administrivia:
To submit articles to comp.lang.perl.announce, send your article to
clpa@perl.com.
Back issues are available via anonymous ftp from
ftp://cil-www.oce.orst.edu/pub/perl/old-digests.
#For other requests pertaining to the digest, send mail to
#perl-users-request@ruby.oce.orst.edu. Do not waste your time or mine
#sending perl questions to the -request address, I don't have time to
#answer them even if I did know the answer.
------------------------------
End of Perl-Users Digest V11 Issue 4261
***************************************