Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
Just another Perl shrine
 
PerlMonks  

Re: Trying to access hash from external perl file

by kennethk (Monsignor)
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 File_a.pl 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.


Comment on Re: Trying to access hash from external perl file
Download Code

Log In?
Username:
Password:

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

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (14)
As of 2014-04-16 19:38 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    April first is:







    Results (433 votes), past polls