Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: hash pm

by fullermd (Priest)
on Nov 30, 2010 at 03:04 UTC ( [id://874419]=note: print w/replies, xml ) Need Help??


in reply to hash pm

You'll need to make it a package variable (our and probably exported, or explicitly call it as Package::varname) instead of a lexical (my).

$MYconf::vars = { <stuff> };

Replies are listed 'Best First'.
Re^2: hash pm
by toniax (Scribe) on Nov 30, 2010 at 03:22 UTC
    Thanks for the info.
    After reading about Perl modules I now realize it is more involved .
    I will just have to read more about it

      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.

        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)

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://874419]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others imbibing at the Monastery: (4)
As of 2024-04-20 03:42 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found