On Fri, May 2, 2008 at 2:54 PM, Levente Kovacs <[EMAIL PROTECTED]> wrote: > Ok, I've reached the level, when I want to do perl modules. I've seen > tutorials with the `h2xs' approach, but the problem is that I don't know what > it EXACTLY does.
Try this simple one: http://search.cpan.org/~rjbs/Module-Starter-1.470/lib/Module/Starter.pm > > I'd like to write a code shared among several simple scripts, as a NON-OO > module, used in single program packege. I'd be happy with some #include style > in C, but I don't know how to do that really. > I have replied this similiar question on this list, just copy it here. You can 'source' or 'include' another perl file from the current one. The ways are like: ######################### # the first way ######################### The first,you can just require a file,because this file didn't be declared as a package,so it doesn't has its own namespace,so all variables in this file can be imported into main package's space. $ cat mydata.pl use strict; our (@key1,@key2); $key1[64]="0xc120718a1ccce7f8"; $key2[64]="0xeadf28cb82020921"; $key1[128]="0xaf503224b6cff0639cf0dc310a4b1277"; $key2[128]="0x3e1fcbd4e91ca24bb276914de3764cdf"; 1; $ cat usedata.pl require 'mydata.pl'; print $key1[64]; ######################### # the second way ######################### The second way,you can declare the config file as a package,and export the needed varibles.When main script use this package,it import those variables automatically. $ cat mydata2.pm package mydata2; use strict; require Exporter; our @ISA = qw(Exporter); our (@key1,@key2); our @EXPORT = qw(@key1 @key2); $key1[64]="0xc120718a1ccce7f8"; $key2[64]="0xeadf28cb82020921"; $key1[128]="0xaf503224b6cff0639cf0dc310a4b1277"; $key2[128]="0x3e1fcbd4e91ca24bb276914de3764cdf"; 1; $ cat usedata2.pl use mydata2; print $key1[64]; ######################### # the third way ######################### Both the first way and the second way are not good.Because your config file is large,the former ways have imported all those large content into your main script.If your main script is run under cgi/modperl which is generally multi-process,your memory could be eated quickly.So the best way is to create an object then multi-process can share the object if this object was not changed later,since object is only located in its own namespace. $ cat mydata3.pm package mydata3; use strict; sub new { my $class = shift; my (@key1,@key2); $key1[64]="0xc120718a1ccce7f8"; $key2[64]="0xeadf28cb82020921"; $key1[128]="0xaf503224b6cff0639cf0dc310a4b1277"; $key2[128]="0x3e1fcbd4e91ca24bb276914de3764cdf"; bless {key1=>[EMAIL PROTECTED],key2=>[EMAIL PROTECTED],$class; } 1; $ cat usedata3.pl use mydata3; my $d = mydata3->new; print $d->{key1}->[64]; -- J. Peng - [EMAIL PROTECTED] Professional Chinese Squid supports http://SquidCN.spaces.live.com/ -- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED] http://learn.perl.org/