in reply to Re: Is "use" same as include?
in thread Is "use" same as include?

Thank you folks.

To answer some question in reply
a) I have about 500 some constants
b) Yes the plan was to use these constants for "stuff like thing "3" in this array means "name".
This is not the right approach for that?
c) Yes I am currently using the Exporter for this. Here is the code (The recipe to export all symbols is a modified version of a reply that I came across in a different post here at perlmonk)
package MyConstants; require Exporter; @ISA = qw(Exporter); our @EXPORT = do { no strict 'refs'; keys %{ __PACKAGE__ . '::'}; }; use constant VAR1 => VAL1; use constant VAR2 => VAL2; #--- 500 more of these 1;
Each of the other modules module1.pm, module2.pm, module3.pm then have
use MyConstants;

Replies are listed 'Best First'.
Re^3: Is "use" same as include?
by Marshall (Canon) on Jul 15, 2009 at 21:46 UTC
    If you intend to export 500 things, then I would argue that there is something fundamentally wrong with the design.

    As what I would call a "sanity check", go look at some HUGE Perl modules. Some of these things have mind-bending, brain-twisting, byzantine complexity, but NONE that I've found have a module that exports 500 things! A dozen? Yeah! Some dozens or even a hundred, maybe! But 500? No!

    Perl has amazing abilities to deal with arrays and complex structures without the use of indicies, without needing a #define statement. Say:

    @stuff = my($low_temp, $high_temp, $average_temp = split(/\s+/,$line); + $stuff[0] is $low_temp. Do I need a #define LOW_TEMP 0\ /*low_temp var*/$stuff[LOW_TEMP]? NO! I just use the variable name that has just been declared: $low_temp. Forget the idea of $stuff[0] or $stuff[LOW_TEMP].

    If you could make a short example of why you need so many global variables, it would be helpful because I don't know how to help you further with the data that I have so far.

Re^3: Is "use" same as include?
by ikegami (Patriarch) on Jul 15, 2009 at 20:27 UTC
    That exports too much. You can't unconditionally export everything that's in the package! Once you fix it, you end up with the code I posted earlier in this thread.