"use" statement inside an eval: problem?

Reply

Join Date: Jun 2006
Posts: 263
Reputation: Mushy-pea is an unknown quantity at this point 
Solved Threads: 1
Mushy-pea's Avatar
Mushy-pea Mushy-pea is offline Offline
Posting Whiz in Training

"use" statement inside an eval: problem?

 
0
  #1
Jan 27th, 2007
Hello everyone. Is it allowed to have a "use" statement inside an eval that is compiled separately to the enclosing program (i.e. eval EXPR, not eval BLOCK). The reason I want to do this is, I have modules of code that I don't want to be compiled every time my script is run as they will not be needed very often. One of them contains Digest::MD5 which is quite bulky. I tried running these modules as child processes with:

  1. $pwd_hash = `perl password_md5.pl $field[1]`;

This worked on my test server, but not on my host server which doesn't seem to allow this kind of behaviour. I'm looking into that issue. I came up with the solution of loading the modules from a file at runtime and passing the code to an eval EXPR. This works with one of them and should be more efficient as it avoids the overhead incurred from starting a new process or thread. The other module includes:

  1. use Digest::MD5;

and this seems to be causing a problem. Is it possible to use "use" inside an eval like this, or will I have to include the MD5 :: Digest code manually? Any advice appriciated.

Steven.
Last edited by Mushy-pea; Jan 27th, 2007 at 5:07 pm.
The one question you should not ask when teaching a new language structure is "Do you understand?". Do you understand?
Reply With Quote Quick reply to this message  
Join Date: Jul 2006
Posts: 1,091
Reputation: MattEvans is a jewel in the rough MattEvans is a jewel in the rough MattEvans is a jewel in the rough 
Solved Threads: 63
Moderator
Featured Poster
MattEvans's Avatar
MattEvans MattEvans is offline Offline
Veteran Poster

Re: "use" statement inside an eval: problem?

 
0
  #2
Jan 28th, 2007
I had a similar intention, and hit exactly the same problem (worked offline but not online); here's what I did:

http://www.daniweb.com/techtalkforums/thread63673.html

That relies on you being able to instantiate an object from the 'use' and return it from the eval... If the module that you use is non OO, perhaps you'll have a problem doing that O_o
Plato forgot the nullahedron..
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC