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 18: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.