in reply to Wish I could include global constants
The code following is a proof of concept that you may extend upon, I have two files, CheeseSpread.pl which has the variables and CreamIt.pl which uses the variables declared in CheeseSpread.pl. Note, the file boundaries are not synonymous with package boundaries so it is possible to declare the variables in one file and then access them from different files.
#!/usr/local/bin/perl #title "Wish I could include global constants" #CheeseSpread.pl use strict; use warnings; package CheeseSpread; BEGIN{ our $name = "Mary"; our $monkish = "MaryFranan"; } 1;
Another thing, Perl has the h2xs utility that you can use to create Modules template - in the current folder - including test files automatically and as quickly as:#!/usr/local/bin/perl use strict; use warnings; require 'CheeseSpread.pl' #imports the package symbol table; print name(); print monkish(); sub name{ return "my name is $CheeseSpread::name\n"; } sub monkish { return "my avatar is $CheeseSpread::monkish\n"; } print "-" x 50, "\n"; # a horizontal rule my $firstName = $CheeseSpread::name; my $monasteryName = $CheeseSpread::monkish; print "my name is $firstName\n"; print "my avatar is $monasteryName\n"; 1;
check the Tutorials and the rich documentation on OO Perl..%h2xs -X -A -n Name::Module
|
|---|