Beefy Boxes and Bandwidth Generously Provided by pair Networks Cowboy Neal with Hat
more useful options
 
PerlMonks  

Re: stronger than eval?

by chorny (Scribe)
on Sep 21, 2006 at 14:51 UTC ( [id://574228]=note: print w/replies, xml ) Need Help??

This is an archived low-energy page for bots and other anonmyous visitors. Please sign up if you are a human and want to interact.


in reply to stronger than eval?

Try
eval { require Cache::File; };
or eval "use Cache::File;";
Use is executed in BEGIN stage, before eval is executed. It is valid even for eval BLOCK. eval SCALAR is other case.

Replies are listed 'Best First'.
Re^2: stronger than eval?
by cephas (Pilgrim) on Sep 21, 2006 at 14:54 UTC
    with require, you'll have to handle import manually.

      I see that as a plus, since it probably doesn't make sense to import from something which is conditionally imported. However, it's not hard to import if so desired.

      BEGIN { eval { require Cache::File } or warn("Proceeding without Cache::File\n"); Cache::File->import(qw( ... )) if Cache::File->can("import"); }

      or

      BEGIN { my @imports = qw( ... ); eval "use Cache::File \@imports" or warn("Proceeding without Cache::File\n"); }

      The BEGIN ensures prototypes are properly loaded.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://574228]
help
Sections?
Information?
Find Nodes?
Leftovers?
    Notices?
    hippoepoptai's answer Re: how do I set a cookie and redirect was blessed by hippo!
    erzuuliAnonymous Monks are no longer allowed to use Super Search, due to an excessive use of this resource by robots.