in reply to Reaped: Re^4: how to create a constant file and use it in other file
in thread how to create a constant file and use it in other file

Here's a fairly simple method:

# The 'source' file ("constants.plx") use constant { FOO => 1, BAR => 2, QUX => 3 };

And in the code, when you want to use these constants:

#!/usr/bin/perl -wl BEGIN { do "constants.plx"; } print "Foo: ". FOO. "\nBar: ". BAR. "\nQux: ". QUX;

This results in

Foo: 1 Bar: 2 Qux: 3

For more info, see "perldoc constant" and "perldoc -f do" (the 'do EXPR' section.)


-- 
Human history becomes more and more a race between education and catastrophe. -- HG Wells

Replies are listed 'Best First'.
Re^6: how to create a constant file and use it in other file
by alexm (Chaplain) on Jul 17, 2008 at 02:00 UTC

    This method is a work-around and it works well, indeed. However, it doesn't address the OP's exporting everything automatically request, IMHO.

    Update: See my proposal above.