including files in perl

B

brad

I have a list of about 100 constants that I want to use in several
files.
I have made this list of constants into a file with extension .hpl as
in .h for perl. anyways, I can use do or require to include this
file, however, the constants are not avaliable to use as if i had
declared them in the calling perl file. To use these constants, I
have to use the eval() function to so i say

KEY_PRESS(KEY_1) normally where KEY_1 is a constant;

when defining KEY_1 in another file and and calling it in function
KEY_PRESS it looks like this:

KEY_PRESS(eval(KEY_1))

I do not want to have to use eval()

why is this happening. This is not the case for variables. This is
only happening for constants. Is there a better way to include other
files into my perl programs. I need to have a comment where the perl
program goes to the file i am calling executes and stores constants
and comes back to the calling file and resumes as normal, require and
do almost do this...
please help
 
W

Walter Roberson

:I have a list of about 100 constants that I want to use in several
:files.
:I have made this list of constants into a file with extension .hpl as
:in .h for perl. anyways, I can use do or require to include this
:file, however, the constants are not avaliable to use as if i had
:declared them in the calling perl file. To use these constants, I
:have to use the eval() function to so i say

:KEY_PRESS(KEY_1) normally where KEY_1 is a constant;

:when defining KEY_1 in another file and and calling it in function
:KEY_PRESS it looks like this:

:KEY_PRESS(eval(KEY_1))

:I do not want to have to use eval()

How are you declaring the constants? Are you declaring them with
"use constant" ? If you are, then they are becoming subroutines and
you shouldn't have to eval() them, provided they are in the correct
namespace.
 
B

Ben Morrow

I have a list of about 100 constants that I want to use in several
files.
I have made this list of constants into a file with extension .hpl as
in .h for perl.

The convention is for such files to have the extension '.ph': perl
header.

Ben
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,009
Latest member
GidgetGamb

Latest Threads

Top