in reply to Problems with the enum Module and File Scoping

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.

Replies are listed 'Best First'.
Re^2: Problems with the enum Module and File Scoping
by ozboomer (Friar) on Sep 03, 2005 at 05:56 UTC
    Ahhh.. 'our' is something I've never seen mentioned anywhere; nothing in the Camel book index, nor in the Llama book index on it... but how handy that's going to be :)

    Making the 'library' into a 'module' is the next step. I don't necessarily want to distribute it but it's probably (the proverbial) 'GoodThing(tm)' to implement these functions via a module, rather than a library; I've not built a module yet so I still have to study-up on that side of things, particularly as regards the exporting of data, subs, etc.

    Many thanks for the helpful suggestions though.


    John