Beefy Boxes and Bandwidth Generously Provided by pair Networks
There's more than one way to do things

Re: Trying to access hash from external perl file

by kennethk (Abbot)
on Jul 11, 2012 at 16:48 UTC ( #981196=note: print w/replies, xml ) Need Help??

in reply to Trying to access hash from external perl file

Well, there are a couple methods, but none is particularly clean from my perspective. The right™ way to do this is to edit to be a module (perlmod), and interact with it programmatically. However, given your spec, I can see two ways to proceed.

  1. If the assignment to %test_hash occurs in the main package and the hash is not lexical (declared with my, see Private Variables via my()), you can use the do mechanism to literally execute the file. Obviously, this will also invoke all the many side effects of the script, which may be undesirable.
  2. You could open the file, strip out the relevant declaration, perhaps using a regex, and then feed it into an eval.

Both of these feel fragile to me, but they will do the job.

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://981196]
and the grasshoppers chirp...

How do I use this? | Other CB clients
Other Users?
Others drinking their drinks and smoking their pipes about the Monastery: (5)
As of 2018-05-24 18:35 GMT
Find Nodes?
    Voting Booth?