in reply to Re^3: An Interesting Gotcha With use/require
in thread An Interesting Gotcha With use/require

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.

Replies are listed 'Best First'.
Re^5: An Interesting Gotcha With use/require
by bart (Canon) on Feb 10, 2005 at 14:15 UTC
    So how was the OP getting a subroutine redefined error in the first place if the import wasn't getting called?

    File/Basename.pm and File/BaseName.pm are both loaded, which on Windows is the same file. Both times it loads its definitions into the same namespace: File::Basename. It's there that the subs are defined twice.

    Just remember the rule of thumb: filenames are case insensitive on Windows, but package names still are case sensitive.

    p.s. tye has created a patch to UNIVERSAL.pm a long time ago, the package all packages inherit from (which matters for import) so your Windows system would catch misused case: Universally unimportant and overused