In Windows, funny things can happen if you get the capitalization wrong, e.g.use win32::ole;. The file is found, because the file opening primitives are case-insensitive by default and nothing in the implementation (perl -> concrete object -> C RTL -> Win32 OS) tells it otherwise.

But, no package is created by that name. The package statement has a different capitalization.

So my musing is this: there should be a warning if the argument to package differs from the file name in case only. Being integrated with the warnings pragma system, you could disable that or make it fatal, if that is what you wanted.

—John

Replies are listed 'Best First'.
Re: use Module and case-insensitive file names
by japhy (Canon) on Jul 30, 2001 at 23:07 UTC
    I'll see what I can do. The pseudocode is:
    include file warn if file ne filename_in_INC_hash;
    I'll see if I can put something in the source that works. It looks like I need to modify pp_ctl.c:pp_require().

    _____________________________________________________
    Jeff japhy Pinyan: Perl, regex, and perl hacker.
    s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

      Why would the filename put in %INC be the "proper" name? I would think it would use whatever the user typed, unless it somehow gets canonized during the search process?

      Yup, it shows the name in the program, not the actual file name:

      [D:\download\public\Perl]perl -MData::Dumper -e "use cArP; print Dumpe +r (\%%INC)" VAR1 = { 'Exporter.pm' => 'D:/Program Files/Perl-5.6/lib/Exporter.pm', 'Carp.pm' => 'D:/Program Files/Perl-5.6/lib/Carp.pm', 'XSLoader.pm' => 'D:/Program Files/Perl-5.6/lib/XSLoader.pm', 'warnings/register.pm' => 'D:/Program Files/Perl-5.6/lib/warn +ings/register.pm', 'warnings.pm' => 'D:/Program Files/Perl-5.6/lib/warnings.pm', 'overload.pm' => 'D:/Program Files/Perl-5.6/lib/overload.pm', 'Data/Dumper.pm' => 'D:/Program Files/Perl-5.6/lib/Data/Dumpe +r.pm', 'cArP.pm' => 'D:/Program Files/Perl-5.6/lib/cArP.pm' };
      Perhaps the right place would be in the code that searches @INC for the module? If it finds something that differs only in case, and it's a case-insentive OS, issue a warning and take the file name that was actually found, so things import properly.

      I don't know why, but Data::Dumper for example just doesn't work if called DaTA::Dumper, even though there is no error of any kind.

      —John

        Ok. I've changed my strategy:
        if ( running_under_windows and Foo.pm loaded and package_Foo doesn't exist ) { warn about case of Foo }
        The reason that
        use Strict; $x = 10;
        is valid is because use is merely:
        BEGIN { require Strict; Strict->import; }
        And on Windows, require Strict goes through fine, thanks to the caseless OS. And import silently fails (as is documented).

        The DaTA::Dumper thing didn't give an error because you didn't turn on warnings. If warnings were on, you'd have seen:

        Name "main::Dumper" used only once: possible typo at -e line 1. Filehandle main::Dumper never opened at -e line 1.

        _____________________________________________________
        Jeff japhy Pinyan: Perl, regex, and perl hacker.
        s++=END;++y(;-P)}y js++=;shajsj<++y(p-q)}?print:??;

(tye)Re: use Module and case-insensitive file names
by tye (Sage) on Jul 31, 2001 at 00:05 UTC