Beefy Boxes and Bandwidth Generously Provided by pair Networks
laziness, impatience, and hubris

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 web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others pondering the Monastery: (5)
As of 2016-10-22 02:00 GMT
Find Nodes?
    Voting Booth?
    How many different varieties (color, size, etc) of socks do you have in your sock drawer?

    Results (291 votes). Check out past polls.