in reply to Clean way to export all constants at once

Specialised Import Lists
# In package global_constants; our %EXPORT_TAGS = (all => \@EXPORT_OK); # In calling code (test.pl): use global_constants(':all');

Replies are listed 'Best First'.
Re^2: Clean way to export all constants at once
by perl_help26 (Beadle) on Jan 30, 2014 at 16:17 UTC

    Thank you for the fast reply :D ... I realize that i still have to list the constants once in global_constants.pm or else it gives me an error

    our @EXPORT_OK = ('CURRENTCHANGE','BLDNUM','STAGEROOTDIR','WEBREPORTDI +R'); our %EXPORT_TAGS = (all => \@EXPORT_OK);

    This is great but can I push it further so that I wouldn't have to list even in global_constants.pm? Thanks a lot.

      Instead of using the constant pragma, I'd use the Readonly module and create a readonly hash which is exported.

      You could even take it a step further and define individual lexical scalars in your module and export a readonly dispatch table of anonymous subs that return the individual scalar values.

      You may also want to read this review http://neilb.org/reviews/constants.html of 21 different modules that can be used to define constants.

        Readonly seems fine but I prefer tobyinc's way ...Thanks for the reply

      You might be able to use Readonly to built up a list of constant names.