This is because your constants only exist in the namespace of your "header" file. What use constant camel => "flea-ridden" actually does is create a subroutine in the caller's namespace that returns the constant (and is normally inlined by the compiler).
Because said subroutine only exists in the namespace of your header file, your main program cannot access it. There are however a number of ways for your program to access this constant. Assuming header.pm contains your constants, and program.pl is your script
- Make header.pm a package that exports your constants:
package header;
@ISA=('Exporter');
@EXPORT=('camel');
use constant camel => 'flea-ridden';
1; # I'm a well-behaving module
Program.pl can then use header; and just access camel as normal.
- Another option is to play symbol table games: program.pl copies the subs into it's own namespace.
# program.pl
use header;
*header::camel=*::camel;
print &camel;
# Note that you have to call camel as a function here.
- I have this nagging feeling that there are some tricks you can pull with eval or require, but I can't think of some right now. Undoubtedly, someone else will soon enough :).
CU Robartes-
-
Are you posting in the right place? Check out Where do I post X? to know for sure.
-
Posts may use any of the Perl Monks Approved HTML tags. Currently these include the following:
<code> <a> <b> <big>
<blockquote> <br /> <dd>
<dl> <dt> <em> <font>
<h1> <h2> <h3> <h4>
<h5> <h6> <hr /> <i>
<li> <nbsp> <ol> <p>
<small> <strike> <strong>
<sub> <sup> <table>
<td> <th> <tr> <tt>
<u> <ul>
-
Snippets of code should be wrapped in
<code> tags not
<pre> tags. In fact, <pre>
tags should generally be avoided. If they must
be used, extreme care should be
taken to ensure that their contents do not
have long lines (<70 chars), in order to prevent
horizontal scrolling (and possible janitor
intervention).
-
Want more info? How to link
or How to display code and escape characters
are good places to start.
|