Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Re^3: Eval/package question

by shmem (Chancellor)
on Jan 21, 2020 at 14:38 UTC ( [id://11111683]=note: print w/replies, xml ) Need Help??


in reply to Re^2: Eval/package question
in thread Eval/package question

(the package variable (%items above) is not available).

It is not, because %items is declared as a my variable and thus available only in the the package itself, not in the main package.

If you have to access it from main, you either have to fully qualify it as %items::items, or provide methods to access it (exporting it, providing accessors or a method which returns a reference to it, etc), but it's hard to say what's best without knowing the whole scenario.

perl -le'print map{pack c,($-++?1:13)+ord}split//,ESEL'

Replies are listed 'Best First'.
Re^4: Eval/package question
by Anonymous Monk on Jan 21, 2020 at 16:26 UTC

    my variables are local to the lexical scope in which they are declared, and can not be accessed outside that scope.

    If you want to access %items outside the file in which it is declared, you need to specify our %items, not my %items. Then you can access it by its fully-qualified name. That is, if it is declared in package Foo you say (e.g.) $Foo::items{Dent} = 'Arthur';.

    In an ideal world the OP would not be mucking around with global variables, but this is not an ideal world.

Log In?
Username:
Password:

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

How do I use this?Last hourOther CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (3)
As of 2024-03-29 04:33 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found