Re: How to 'conditionally' use a specified module
- From: "Paul Lalli" <mritty@xxxxxxxxx>
- Date: 16 Nov 2006 09:32:55 -0800
danny wrote:
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.
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.
I have no idea what makes you think you can't use require. Can you
explain?
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.
No, it really didn't. If you think it did, you didn't test well
enough. Your statement that assigns 'yes' or 'no' to $use_cache
executes at runtime. The if pragma executes at compile time. At the
time you check to see if $use_cache is equal to 'yes', $use_cache is
undefined. If you were using warnings, Perl would have told you this.
Change
my $use_cache = 'no';
to
my $use_cache = 'yes';
and you will see that the module is still not loaded.
Paul Lalli
.
- Follow-Ups:
- Re: How to 'conditionally' use a specified module
- From: usenet
- Re: How to 'conditionally' use a specified module
- References:
- How to 'conditionally' use a specified module
- From: danny
- Re: How to 'conditionally' use a specified module
- From: usenet
- Re: How to 'conditionally' use a specified module
- From: Uri Guttman
- Re: How to 'conditionally' use a specified module
- From: danny
- How to 'conditionally' use a specified module
- Prev by Date: Re: Perl - Joining of Binary values
- Next by Date: Re: Perl - Joining of Binary values
- Previous by thread: Re: How to 'conditionally' use a specified module
- Next by thread: Re: How to 'conditionally' use a specified module
- Index(es):
Relevant Pages
|