Marc Lucksch wrote:
Stanisław T. Findeisen schrieb:

Subject: 2 files, 1 package, shared constants

Hello there

My application consists of several files. Some of them are to be run as
CGI scripts, the others from command line. There is also a "common" file
with constants and shared routines.

The question is: what is the most standard way to export constants from
that common file so that they could be used in the other files?

The Exporter.

That's probably true when you export symbols between packages.

<snip>

I would do something like this.
package MyPackage;

use warnings;
use strict;
use constant {
    MY_FIRST_CONSTANT => 'hello world!'
};
use Exporter;

our @EXPORT = qw/MY_FIRST_CONSTANT
         $MY_SECOND_CONSTANT
         routine1
        /;
#...@export_ok would be better

In this case there is only one package. Would you still bother with Exporter? Why?

--
Gunnar Hjalmarsson
Email: http://www.gunnar.cc/cgi-bin/contact.pl

--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/


Reply via email to