include - Perl : constant & require -
i have config file (config.pl) constants :
#!/usr/bin/perl use strict; use warnings; use net::domain qw(hostname hostfqdn hostdomain domainname); use constant url => "http://".domainname()."/"; use constant cgibin => url."cgi-bin/"; use constant css => url."html/css/"; use constant ressources => url."html/ressources/"; ...
and use these constants in index.pl, index.pl starts :
#!/usr/bin/perl -w use strict; use cgi; require "config.pl";
how use url, cgi... in index.pl ?
thanks,
bye
edit
found solution :
config.pm
#!/usr/bin/perl package config; use strict; use warnings; use net::domain qw(hostname hostfqdn hostdomain domainname); use constant url => "http://".domainname()."/"; use constant cgibin => url."cgi-bin/"; 1;
index.pl
begin { require "config.pm"; } print config::url;
end
what want here setup perl module can export from.
place following 'myconfig.pm':
#!/usr/bin/perl package myconfig; use strict; use warnings; use net::domain qw(hostname hostfqdn hostdomain domainname); use constant url => "http://".domainname()."/"; use constant cgibin => url."cgi-bin/"; use constant css => url."html/css/"; use constant ressources => url."html/ressources/"; require exporter; our @isa = 'exporter'; our @export = qw(hostname hostfqdn hostdomain domainname url cgibin css ressources);
and use it:
use myconfig; # means begin {require 'myconfig.pm'; myconfig->import}
by setting @isa
exporter
in myconfig
package, setup package inherit exporter
. exporter
provides import
method implicitly called use myconfig;
line. variable @export
contains list of names exporter
should import default. there many other options available in perl's documentation , in documentation exporter
Comments
Post a Comment