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:

$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:

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.


I had a similar intention, and hit exactly the same problem (worked offline but not online); here's what I did:


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

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.