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

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?

  • Comment on Re^2: An Interesting Gotcha With use/require

Replies are listed 'Best First'.
Re^3: An Interesting Gotcha With use/require
by chromatic (Archbishop) on Feb 09, 2005 at 18:16 UTC

    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.

        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