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

Dear Monks,
How I can detect the case sensitivity on modules name while using in the program on windows?
consider following
Case 1: (Incorrect, No Error)
use strict; use warnings; use File::BaseName;
Case 2: (Corrct, No Error)
use strict; use warnings; use File::Basename;
Case 3: (InCorrect, Error)
use strict; use warnings; use File::XBasename;
Case 2 is correct, while case 1 and case 3 represents the modules that doesn't exist. Only case 3 gives the error, while case 1 should also give the error in my opinion. Of course, case 1 complains when a function is used such as $dir = dirname($fullpath);

artist

Replies are listed 'Best First'.
Re: Case Insensitivity on Windows (done)
by tye (Sage) on Jul 18, 2003 at 18:52 UTC
Re: Case Insensitivity on Windows
by ChrisS (Monk) on Jul 18, 2003 at 18:16 UTC
    The code below might be what you need to see if a module is installed.
    use ExtUtils::Installed; my $inst = ExtUtils::Installed->new(); my @missing = $inst->validate("File::BaseName"); print @missing;
    In this case, the @missing array shows:
    File::BaseName is not installed...
    The validate method returns a list of the missing files. Some of the other methods could help, too.
Re: Case Insensitivity on Windows
by sgifford (Prior) on Jul 18, 2003 at 18:17 UTC

    I assume that the reason you want to do this is to make sure that you've loaded a filename that matches the package name, since otherwise the module won't work.

    You can do this by looking at the hash %packagename:: and making sure it has more than just the one import method that Perl puts in there. For example:

    #!/usr/bin/perl use CGI; die "CGI not loaded" unless (keys(%CGI::) > 1); use cGi; die "cGi not loaded" unless (keys(%cGi::) > 1);

    If you really want the filename, you can look the module up in the %INC hash, then open up its parent directory and scan the list of filenames returned for the one you want.