Warning: Don't use the following *as is*, you might get beaten. But for the sake of TIMTOWTDY...
See note at the end.

I concur with Marshall, that having 500 symbols to export smells like a design flaw. But that must not be the case. You could use perl's subroutine of last resort - AUTOLOAD - and not export anything explicitly...

package MyConstants; use strict; our $AUTOLOAD; sub import { my $package = shift; if ($_[0] eq 'AUTOLOAD') { my $caller = caller; no strict 'refs'; *{$caller.'::AUTOLOAD'} = \&{$package.'::AUTOLOAD'}; } } # Constants use constant { NIL => 0, FOO => 1, BAR => 2, }; sub AUTOLOAD { (my $func = $AUTOLOAD) =~ s/.*:://; no strict 'refs'; *{$AUTOLOAD} = \&{__PACKAGE__.$func}; goto &$func; } 1;
#!/usr/bin/perl; use MyConstants qw(AUTOLOAD); use strict; use constant { NIL => -1 }; my @ary = qw(ene mene muh); print join(" => ", @ary[FOO(),NIL()]),$/; __END__ mene => muh

... to get the constants when they are needed, at the expense of explicitly marking the constants as function calls (they are that anyways), e.g. FOO(), which otherwise would be interpreted as barewords.

But I myself would consider that bad practice, since it is too obscure. I'd use that technique only for development, dump the imported constants in the sub AUTOLOAD and, in the final version, use that output to import the constants explicitly in the importing package.


In reply to Re: Is "use" same as include? by shmem
in thread Is "use" same as include? by Anonymous Monk

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



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.