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

salut, i have a little problem with @INC when using the activestate perl dirstribution so i wrote a little script:
use strict; use warnings 'all'; my $found; for my $in_path (@INC){ next if ! -e $in_path."\\Win32API\\File.pm"; print "found module in $in_path ...\n"; $found = 1; last; } if ($found){ require 'Win32API::File'; my @drv = map{s/\\$//;lc} Win32API::File::getLogicalDrives(); print @drv; }
but unfortunately this gives me
H:\>perl testINC.pl found module in C:/Perl/site/lib ... Can't locate Win32API::File in @INC (@INC contains: C:/Perl/lib C:/Per +l/site/lib .) at testINC.pl line 14.
strange, no? can anyone help me?

----
NaSe
:x

Edit kudra, 2002-08-21 Changed title

Replies are listed 'Best First'.
Re: strange things happen
by jmcnamara (Monsignor) on Aug 21, 2002 at 09:51 UTC

    The problem is that Win32API::File means different things when it is quoted and when it is a bareword. See require.

    A better approach might be to use eval and check the value of $@:

    eval {require Win32API::File}; if (not $@) { my @drv = map {s/\\$//;lc} Win32API::File::getLogicalDrives(); print @drv; }

    --
    John.

    "Strange things happen when you're not around" - Billy Bragg

Re: strange things happen
by blakem (Monsignor) on Aug 21, 2002 at 09:51 UTC
    Try replacing:
    require 'Win32API::File';
    with either one of:
    require Win32API::File;
    OR
    require 'Win32API/File.pm';
    and read the require docs very carefully....

    -Blake

Re: strange things happen
by smitz (Chaplain) on Aug 21, 2002 at 09:55 UTC
    This works fine for me:

    use strict; use warnings 'all'; my $found = 0; for my $in_path (@INC){ next if ! -e $in_path."\\Win32API\\File.pm"; print "found module in $in_path ...\n"; $found = 1; last; } if ($found == 1){ use Win32API::File; my @drv = map{s/\\$//;lc} Win32API::File::getLogicalDrives(); print @drv; }

    Giving these results:
    found module in C:/Perl/site/lib ... a:c:d:e:p:u:

    SMiTZ

    Update: All though this works OK, its pointless putting use into a conditional block as it gets loaded at compile time. Testing for its existance after perl has attempted to load it seems a bit superfluous. Ooops, thanks jmcnamara.
Re: problem with @INC when using activestate perl
by NaSe77 (Monk) on Aug 21, 2002 at 12:59 UTC
    thank you all....
    when erasing the two "'"'s around Win32API::File it worked

    ----
    NaSe
    :x