Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Re: Re: the #include business

by esh (Pilgrim)
on Aug 23, 2003 at 16:43 UTC ( [id://286073]=note: print w/replies, xml ) Need Help??


in reply to Re: Re: the #include business
in thread the #include business

You could also so something simpler like keep your constants in a package namespace and refer to them that way from other packages and the main daemon. This reduces clutter in the global namespace and only requires the file to be processed once for all of them.

For example:

#file1.pl #!/usr/bin/perl -w use strict; use Constants; print "ONE=", $Constants::ONE, "\n"; print "TWO=", $Constants::TWO, "\n"; print "THREE=", $Constants::THREE, "\n"; #Constants.pm package Constants; $Constants::ONE = 1; $Constants::TWO = 2; 1;
A big problem with this approach is that you don't get compile time checking when you refer to a variable in another package. This is shown above with $Constants::THREE which only causes a problem at run time (at least in Perl 5.6.1).

Even with that drawback, this is a technique I use.

-- Eric Hammond

Replies are listed 'Best First'.
Re: Re: Re: Re: the #include business
by Anonymous Monk on Aug 24, 2003 at 00:14 UTC

    Constants that you can change...what a novel idea! Of course, you could just do it the "normal" way and use subroutines that are prototyped with no params (or of course use contant).

    package Constants; sub ONE() { 1 } sub TWO() { 2 }

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others meditating upon the Monastery: (4)
As of 2024-04-19 14:09 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found