PegLeg has asked for the wisdom of the Perl Monks concerning the following question:

ok, so I'm trying out a new package. If I unshift its directory onto @INC, then I still get an error during compilation that package is unfound, which makes sense to me. unshift(@INC,'/temp/packdir/') ; use MyNewPackage ; How can I get this to work? thanks

Replies are listed 'Best First'.
Re: unshift onto @INC
by KM (Priest) on Jun 22, 2000 at 00:39 UTC
    Or:
    use lib '/temp/packdir';

    Which pretty much does the same thing, and I personally like better.

    Cheers,
    KM

Re: unshift onto @INC
by btrott (Parson) on Jun 22, 2000 at 00:35 UTC
    You need to do the unshift in a BEGIN block:
    BEGIN { unshift @INC, "/temp/packdir"; }
    This is necessary because use is a compile-term directive. From the use docs, you find that use Module is exactly equivalent to
    BEGIN { require Module; import Module LIST; }
RE: unshift onto @INC
by Adam (Vicar) on Jun 22, 2000 at 01:14 UTC
    I have to agree with KM, either use the "use lib" pragma or edit your first line to read:
    #! perl -W -I /temp/packdir/
    Which of course only works on machines that use that line.
      I think you mean to have a lower-case 'w' there. -W does something in perl 5.6.x I beleive, but not in perl 5.005.
        Correct, that is a 5.6 thing. I really wish people here would stick with -w in examples to ensure there is no confusion, since noone seems to comment 'This is for 5.6 and above only' when they do it.

        Cheers,
        KM