I asked about @INC a good week and a half ago......
What's wrong with the ActivePerl e-mail server??

Mk

-----Original Message-----
From: [EMAIL PROTECTED]
[mailto:[EMAIL PROTECTED]]On Behalf Of Brent Dax
Sent: Thursday, January 17, 2002 7:33 PM
To: [EMAIL PROTECTED]; Perl
Subject: RE: @INC


[EMAIL PROTECTED]:
# # add path to @INC
# push(@INC, 'p:\PERL\TimeBase');
#
# # Folio utilities
# use Folio::Utilities qw(
#     remFolTags
#     stdChars
# );

(Warning: this message is subtitled "Everything You Didn't Want To Know
About 'use'".  :^) )

You've been bitten by the compile-time behavior of 'use'.  'use'
(effectively) inserts the code of the module in its place, then calls an
import() function.  (Actually, "use Module 'foo'" becomes "BEGIN
{require Module; Module->import 'foo';}", but the effect is basically
the same.)  However, the push occurs at runtime, _after_ the 'use' has
already happened.  See the problem?

The solution is not to use @INC directly.  Just use the 'lib' module:

        use lib 'p:\PERL\TimeBase';

        use Folio::Utilities qw(
                remFolTags
                stdChars
        );

If you're hell-bent on using @INC directly, the BEGIN block is your
friend:

        BEGIN { push(@INC, 'p:\PERL\TimeBase'); }

        use Folio::Utilities qw(
                remFolTags
                stdChars
        );

This becomes:

        BEGIN { push(@INC, 'p:\PERL\TimeBase'); }

        BEGIN {
                require Folio::Utilities;
                Folio::Utilities->import qw(
                        remFolTags
                        stdChars
                );
        }

which works because BEGIN blocks are executed in order.

--Brent Dax
[EMAIL PROTECTED]
Parrot Configure pumpking and regex hacker

<obra> mmmm. hawt sysadmin chx0rs
<lathos> This is sad. I know of *a* hawt sysamin chx0r.
<obra> I know more than a few.
<lathos> obra: There are two? Are you sure it's not the same one?


_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl
_______________________________________________
ActivePerl mailing list
[EMAIL PROTECTED]
http://listserv.ActiveState.com/mailman/listinfo/activeperl

Reply via email to