I've never used
enum but it seems to work roughly the same way that
constant does - namely, it creates subroutines with the names that you give it, and these subroutines do nothing but return a value. Many of the experienced people here don't really like to use these modules, finding it easier to just use ordinary scalar variables instead which, as you note, are identified with a '$'. You're right that '&' is only for calling subroutines - what isn't so obvious is that that's how
enum works. So in that case your code within slib.pl would be more like
our $SM_UNK_REC = 1;
our $SM_HDR_REC = 2;
our $SM_TTL_REC = 3;
Use "our" to declare these variables (instead of "my") so that they become visible to other packages, which is what you want. Now you can access these variables in just the way you tried:
$stat = &slib::ABC($slib::SM_HDR_REC);
By the way, a stylistic note - the ampersand in front of slib::ABC is almost definitely not needed.
If you want, you can also make the constants available from the calling program directly by changing slib.pl to slib.pm and having it look a bit like this:
package slib;
use Exporter;
our @ISA = qw/Exporter/;
our @EXPORT_OK = qw/ABC $SM_UNK_REC $SM_HDR_REC $SM_TTL_REC/;
...
and from your main program
use slib qw/ABC $SM_UNK_REC $SM_HDR_REC $SM_TTL_REC/;
$stat = ABC(SM_HDR_REC);
or whatever you want.
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: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.