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
_______________________________________________
Perl-Win32-Admin mailing list
[EMAIL PROTECTED]
To unsubscribe: http://listserv.ActiveState.com/mailman/mysubs