Having said that, alarm bells go off in my brain as to how many of these constants do you have? 10,50,100?
The reason that I'm asking is that in C, a lot of of these #define things have to do with a) memory limits (like array bounds..MAX_LINE_BYTES, etc) or b) stuff like thing "3" in this array means "name". Using Perl constants for either a or b is not the right Perl way.
So anyway, say you have a dozen of these things....the below code will do it. The code in your modules would look like use MyConstants(VAR1 VAR3); I LOVE C, but this is not C. You don't have to import any variable into your name space that you don't need. In C there will be hundreds if not thousands of vars imported into your compile name space via the .h files! In Perl, you can specify which vars you want to import, below this is specified by @EXPORT_OK. If you want all of them, then put them in the @EXPORT list (the default export/import list). Also, in Perl there is really no such thing as a truly "private variable". Even if VAR3 is not exported, it can still be accessed via $MyConstants::VAR3, assuming that $VAR3 has package scope which is what "our" does.
Anyway the below scheme should work fine for like a dozen vars.
Update:#file MyConstants.pm use strict; use warnings; package MyConstants; use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $VERSION); use Exporter; our $VERSION=0.1; our @ISA = qw(Exporter); our @EXPORT = qw(); #default export our @EXPORT_OK = qw(VAR1 VAR2 VAR3); #by request export our $VAR1 ="something"; our $VAR2 ="something_else"; our $VAR3 ="something_way_else"; 1;
In reply to Re: Is "use" same as include?
by Marshall
in thread Is "use" same as include?
by Anonymous Monk
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |