----- Original Message -----
From: "King, Jason G" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Wednesday, February 12, 2003 5:42 PM
Subject: RE: selective use of modules
Neil writes..
>This is a general question as opposed to 'I need help with...'
>
>The code below does what is expected - whether if(1) or if(0)
>
>use strict;
>use warnings;
>use Data::Dumper;
>my $object;
>
>if (1)
> {
> use CreateYourWeb::Logger;
> $object = CreateYourWeb::Logger->new(logfile=>'c:/test.log');
> }
>else
> {
> use CreateYourWeb::Trapper;
> $object = CreateYourWeb::Trapper->new(trapper=>'trapcatcher');
> }
>print Dumper $object;
>
>
>What I want to know - but I can't seem to find the right
>perldoc - or I have and just don't 'get it', ... is this ...
>
>When selectively using modules in this way - does the path not
>taken still end up with the module being compiled and stored
>as potential code ?
Yes, I'm not sure whether you're aware of Perl's optimisation for
conditionals based on literal values and that was why you asked this
question. If so then the "yes" is because the BEGIN blocks generated by
the 'use's are done before Perl optimises the 'else' out of the code, so
both modules are included. You can test this by running a
CreateYourWeb::Trapper function inside the if(1) part of the code. It
will not cause an error.
If you weren't aware of the optimisation and were just wondering how to
conditionally include modules in your code, then have a look at the
documentation for use and for require. Require is what you want for that
sort of thing.
--
Jason King
Thanks Jason,
I need to hit the docs again - although everything you said was confirmation
of what I thought I understood.
You may get a better understanding of why I am after this if you read my
reply to Merrill Cornish.... but basically some of the modules or scripts I
would be using would themselves be using other modules - and I am never sure
which or when due to the dynamic nature of the big picture.
If it is not real clear - I'll try my hand at explaining better ....I
appreciate the help.
Neil
_______________________________________________
Perl-Win32-Admin mailing list
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs