Re: How to 'conditionally' use a specified module



Uri Guttman wrote:
"u" == usenet <usenet@xxxxxxxxxxxxxxx> writes:

u> use if ($use_cache eq 'yes'), Cache::SizeAwareFileCache;

that will still fail if the boolean value is set at runtime since use
executes at compile time. this is where require is better as it only
executes at runtime. (of course string eval breaks all those rules).

so to the OP, you need to call require and not use there.


Hi Uri,

Thanks for the advise. Unfortunately I can't use require because the
code I fixed is inside a module and I can only reference with
MyPackage::This and MyPackage::That.

In my particular situation, David Filmer's tip worked perfectly.

my $use_cache = 'no';
use if ($use_cache eq 'yes'), 'Cache::SizeAwareFileCache';
That fixed everything.

But I'll remember your advise in case next time I needed to use
something like this and couldn't get it to work with if pragma.

--Danny

.



Relevant Pages

  • Re: Still not getting it.
    ... Compile time for the creator, ... Vector executes is creates a definition. ... 1024 Vector stimulus OK ... gain and response arrays. ...
    (comp.lang.forth)
  • Re: How to conditionally use a specified module
    ... that will still fail if the boolean value is set at runtime since use ... executes at compile time. ... The if pragma executes at compile time. ...
    (perl.beginners)
  • Re: How to process contents of a list variable through a macro ?
    ... > But the compiler executes the Macros during compile time. ... A DEFPARAMETER does get executed at compile time. ... It is a DEFVAR declaration that dosn't. ...
    (comp.lang.lisp)
  • VB6 SP6 BUG Using NOT keyword??!!!
    ... I have a function (which returns a Boolean) call that checks for an existing Internet connection, and executes a block of code if the connection does not exist, as such: ... Whenever the CheckInternet function returns TRUE, the condition executes anyway. ... Dim bResult As Boolean ...
    (microsoft.public.vb.bugs)
  • Re: OT: Linux Interview Questions
    ... executes them sequentially as long as none of them fail, ... return a 1 and the whole statement will fail. ... I find bash scripting very cryptic and I don't mean that as ... To UNSUBSCRIBE, email to debian-user-REQUEST@xxxxxxxxxxxxxxxx ...
    (Debian-User)