SPUG: Constants
Matt Tucker
tuck at whistlingfish.net
Mon Jul 10 19:06:54 CDT 2000
-- Andrew Sweger <andy at n2h2.com> spake thusly:
> On Jul 10, 2000 @ 3:37pm, Jonathan Gardner wrote:
>
>> 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.
>
> Perl's 'use constant pragma (which is a module) uses named
> subroutines as the constants. They become "inlined" if it's obvious
> to perl that the return value is indeed a constant.
You can also, if you don't want to "use constant" (and can't or won't
use lexical variables) alias your package variables to constant values:
package Foo;
use strict;
use vars qw($bar);
*bar = \"This is a constant string\n";
package main;
print $Foo::bar; <-- this would work
$Foo::bar = "This is a new value\n"; <-- this would die
- Matt
- - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
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