SPUG: Constants

Jonathan Gardner gardner at sounddomain.com
Mon Jul 10 17:37:16 CDT 2000

We're using mod_perl on apache and we want to improve the performance and
ease of programming our scripts. One of the ideas was centralizing important
urls in their appropriate modules. The problem is that having a module run
on several scripts, the chance of having a script actually change a variable
in that module is good, and since the modules are persistent, the change
would remain after the script finished. So we need some way of protecting
our variables from being changed, while keeping them easy to access.

If this were C++ (and it isn't) I would define those variables as const. The
perl constant pragma (or is it a module? I am not sure...) works but it is
clunky to use. You can't use those constants as regular variables, unless
you jimmy them around.

My idea was to build a module called something like:

Then when you wanted to make a variable constants, you would do it like

use ConstantScalar;

my $constant_scalar;
tie $constant_scalar, 'ConstantScalar';

I could easily build similar modules for arrays and hashes.

The variable would work just as any other, except that when you went to
change it, it would die right away.

Is there something out there that is easier to use than this?

Jonathan Gardner
SoundDomain, Inc.
gardner at sounddomain.com
tel: 425-820-2771 x23
fax: 425-820-5951

 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
     POST TO: spug-list at pm.org       PROBLEMS: owner-spug-list at pm.org
      Subscriptions; Email to majordomo at pm.org:  ACTION  LIST  EMAIL
  Replace ACTION by subscribe or unsubscribe, EMAIL by your Email-address
 For full traffic, use spug-list for LIST ; otherwise use spug-list-digest
  Seattle Perl Users Group (SPUG) Home Page: http://www.halcyon.com/spug/

More information about the spug-list mailing list