http://www.perlmonks.org?node_id=874422


in reply to Re^2: hash pm
in thread hash pm

The important bit to remember in this case is that "modules" and "packages (namespaces)" and "files" often exist in 1:1:1 ratios, but don't necessarily have to. That's just the common and convenient way.

What you want is for this variable to be visible from outside this {file,module}. Using my is wrong for that, since my creates a lexical variable, which is limited to the current scope (and the largest scope it can occupy is a file, so it can't be gotten at from outside).

So it has to be a package variable of one sort or another. It can live in the package of this module, and be exported (via Exporter, or manual trickery if you're insane). It can live in that package and not be exported, and thus accessed only by its fill name $My::Package::vars. Or you can just invent a package namespace for it, and call it $MyConfig::vars everywhere. You may have to read up on how packages work in perl if that doesn't make sense...

The most obvious (and probably right) Way To Do It in this case is just to make it a package variable in that module's package, declare it in that file with our instead of my, and either use Exporter or refer to it by full name in other files. The various other solutions mentioned above are comparatively less likely to be the best choice.

Replies are listed 'Best First'.
Re^4: hash pm
by toniax (Scribe) on Nov 30, 2010 at 15:48 UTC
    Thanks for all the info I found some good links that explain pm files tutorialspoint.com and
    wikipedia.org I would use perldoc but they are like the Unix man pages,
    good if you forget something and need to look it up , not really too good for learning (well for me anyway)