Beefy Boxes and Bandwidth Generously Provided by pair Networks
go ahead... be a heretic
 
PerlMonks  

comment on

( [id://3333]=superdoc: print w/replies, xml ) Need Help??
I am working on a program that has several hundred constants and I'm trying to figure out a good way to include those via a required file or a used module. I've run into problems and looking for advice.

If I require a file full of constants in g1.inc like

use constant FAILURE_CONF => 1; use constant FAILURE_EVENT => 2; use constant OPEN_REQ => 3; use constant OPEN_CONF => 4; 1;
And use it like

use strict; require "g1.inc"; if ( 3 == OPEN_REQ ) { print "Code is OPEN_REQ\n"; } else { print "Code is NOT OPEN_REQ\n"; }

I receive: 'Bareword "OPEN_REQ" not allowed while "strict subs"'. I had thought for some reason requiring a file is like inserting that code at that spot in the script. Is it a compiletime vs runtime issue?

If I use a module, what is the briefest way to pass my large number of declared constants into the main namespace without retyping everyone of them into @EXPORT?

I await your witty wisdom. :-)


In reply to How to include a large number of constants? by noslenj123

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post; it's "PerlMonks-approved HTML":



  • 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.
Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others goofing around in the Monastery: (1)
As of 2024-04-25 04:21 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found