Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl-Sensitive Sunglasses

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]
[Corion]: A good morning to everybody ;)

How do I use this? | Other CB clients
Other Users?
Others exploiting the Monastery: (3)
As of 2017-12-11 08:44 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (288 votes). Check out past polls.