in reply to An Interesting Gotcha With use/require

It is purely a case-sensitivity issue. To Perl, File::BaseName and File::Basename are two different namespaces. As modules, they would be handled by File/BaseName.pm and File/Basename.pm (ordinarily). To Windows, however, those two files are the same.

Perl won't load a module if it's already in %INC, but Perl doesn't see an entry for 'File/BaseName.pm', only for 'File/Basename.pm'.

For an interesting artifact of this anomoly, try running this code:

use Strict; $foo = 10;
and see what happens. See if you can figure out why.
_____________________________________________________
Jeff japhy Pinyan, P.L., P.M., P.O.D, X.S.: Perl, regex, and perl hacker
How can we ever be the sold short or the cheated, we who for every service have long ago been overpaid? ~~ Meister Eckhart

Replies are listed 'Best First'.
Re^2: An Interesting Gotcha With use/require
by fireartist (Chaplain) on Feb 09, 2005 at 16:55 UTC

    That runs silently for me.
    I did a case-insensitive search for files, to check for any Strict.pm and only found "C:\perl\lib\strict.pm"

    So, it must be loading strict.pm successfully as there's no errors/warnings, but 'strict' isn't catching the undeclared variable.

    I'm stumped! What's going on then?

      Ponder the difference between strict->import() and Strict->import().

        Of course! It appears 'import' is a special case, presumably because many modules don't define it, yet it's always called by 'use'.

        C:\>perl -w -MStrict -le "Strict->import" C:\>perl -w -MStrict -le "Strict->foo" Can't locate object method "foo" via package "Strict" (perhaps you forgot to load "Strict"?) at -e line 1.

        So how was the OP getting a subroutine redefined error in the first place if the import wasn't getting called?

        FooBar.pm

        package FooBar; require Exporter; @ISA = qw(Exporter); @EXPORT_OK = qw(foo); sub foo { print "foo called\n"; } 1;

        test1.pl

        #!/usr/bin/perl use strict; use warnings; use FooBar qw(foo); foo();
        > foo called

        test2.pl

        #!/usr/bin/perl use strict; use warnings; use foobar qw(foo); foo();
        > Undefined subroutine &main::foo called at foo.pl line 7.

        This suggests to me that the File::Basename->import would have worked, but the File::BaseName->import would not have worked, thus redefining nothing.