require would import the symbols and semantics from the package that has the variables at run time, Scoping in Perl is not strictly global, it rather restricts the variables to the package space (which can spread across files), of course it is more robust to control symbols export and import with the Exporter module as ikegami indicated.

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;
#!/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;
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:
%h2xs -X -A -n Name::Module
check the Tutorials and the rich documentation on OO Perl..


Excellence is an Endeavor of Persistence. Chance Favors a Prepared Mind.

In reply to Re: Wish I could include global constants by biohisham
in thread Wish I could include global constants by maryfranan

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.