Stanisław T. Findeisen schrieb:
-----BEGIN PGP SIGNED MESSAGE-----
Hash: SHA1
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.
package MyPackage;
use warnings;
use strict;
use constant {
~ MY_FIRST_CONSTANT => 'hello world!'
};
*MY_SECOND_CONSTANT = [1, 3, 7];
*MY_SECOND_CONSTANT = \729;
sub routine1 {
~ print "Hello from routine1! $MyPackage::MY_SECOND_CONSTANT\n";
}
This is scary, what is with the typegobs there?
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
our $MY_SECOND_CONSTANT = [1, 3, 7];
sub routine1 {
print "Hello from routine1! $MY_SECOND_CONSTANT\n";
}
== one.pl ==
use MyPackage;
routine1();
print MY_FIRST_CONSTANT;
print $MY_SECOND_CONSTANT;
see perldoc Exporter
--
To unsubscribe, e-mail: beginners-unsubscr...@perl.org
For additional commands, e-mail: beginners-h...@perl.org
http://learn.perl.org/