in reply to Trying to access hash from external perl file

Ok thanks for all the replies. Yes, there is a typo in my code. Sorry about that, it has been corrected.

Also, there isn't a package keyword used File_a.pl so it isn't in any specified namespace. The hash does have a lexical scope. I edited the code to reflect that as well.

To clarify further, I can't modify File_a.pl

I tried the "do" keyword and couldn't access the data. Perhaps I'll try the slurp keyword.

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

Replies are listed 'Best First'.
Re^2: Trying to access hash from external perl file
by kennethk (Abbot) on Jul 11, 2012 at 19:06 UTC

    Well, seeing as you fail the conditions on option 1 I gave in Re: Trying to access hash from external perl file, that leaves a regular expression/eval combo after slurping the file. For the line you've posted above, you could use /(\Qmy %test_hash = (\E.*)/ to grab the necessary information. However, this would break if for example, the hash definition was on multiple lines or whitespace differed in any way from what you posted. All of these can be overcome with changes to the regex, but you need to know the specific use case, and presumably how this script might change in the future. And this whole approach presumes that the hash is defined completely in the statement in which it's declared.


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