Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re^2: Perl "Constants"

by vessko (Initiate)
on Feb 03, 2011 at 23:04 UTC ( [id://886093]=note: print w/replies, xml ) Need Help??


in reply to Re: Perl "Constants"
in thread Perl "Constants"

Small problem is that these are package variables (not 'my'-able). Under 'use strict' U have to 'our' them. In case U want the freedom to choose between package or lexical, I use this:
use CONSTANT; CONSTANT my $E => 2.73, my $PI => 3.14, my $CREDO => 'The dream of the slave is...to become master +and have slaves'; # Oops! Wrong CREDO ;) $CREDO = 'In $$$ we trust!'; # will ERROR out ;) # and U can: print "I still believe that '$CREDO!'\n"; #where package CONSTANT; use Carp; use Exporter; use Tie::Scalar; @ISA = qw(Tie::StdScalar Exporter); @EXPORT = qw(CONSTANT); # sub CONSTANT {my $i=0;tie $_[$i++],__PACKAGE__,$_[$i++] while $i<@_} sub CONSTANT {tie $_[$.++],__PACKAGE__,$_[$.++] while $. < @_} # If you want to know if something is tied somewhere ;) # sub REF {@_ > 1 ? '' : ref tied $_[0] || ref $_[0]} sub STORE {confess "constants are READ ONLY!"}; 1; vess

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://886093]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others taking refuge in the Monastery: (6)
As of 2024-03-29 05:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found