Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations wOOdy-Soft on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to share "constant" among many modules

Status
Not open for further replies.

rubis

Programmer
Jun 21, 2001
54
GB
Hi,

I want to share the same constants among 3 modules e.g. Module A, B and C use the same constant $x. Could u pls suggest me how to do it?

Thanks,
 
There is only the method of how to share the variable but what I want to share is "constant".. any suggestion pls??
 
Oh so you mean, for example, for
Code:
use constant three => 3;
you want each module to share the same 3 rather than each using their own individual 3? :)

jaa
 
Oops, I hit 'submit' instead of 'preview'. For what you are trying to do you should probably use a conf file that each module reads.

jaa
 
How about setting up a symbolic link, and reading the value of that?
 
To Justice41...

yes. Many modules use the same constant so I don't want to declare each constant seperately in each module as it is not a good idea to modify it later on. For the config file, u mean I should read the value from the file and then keep it in the constant variable?? Is there a way to declare the constant in one module (let say the module that keeps all share constants) and then the other module can see these constants??

To PaulTEG...

You mean set the symbolic link in one module and let the other modules read it??

 
Legacy of VMS programming
We used logicals (symlinks) to store filenames, and by shelling a process to change the value we could switch between different datasets using the same logicals in the code. Later we used logicals to point to printers, and finally environemnt variables.
The logicals (in VMS) were set in the startup script for the machine, were visible to all processes on the machine with the correct rights.
The symlink might map to a file, but if the constant files are created what odds.
This probably wouldn't work on a Win32 platform, actually on further consideration without serious admin rights to the server it probably wouldn't work at all
Regards
 
So many choices, so little time

create a perl script to hold your constants, called const.pl
Initialise your constants, and then in modules A, B and C

add the following line

require const.pl

HTH
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top