I have recently encountered an interesting gotcha from the use/require functions. I had just added a library function to my general use library when I suddenly started getting a redefined subroutine warning for File::Basename (see below) from a program that had been running warning free until that moment. Both the main program and the new library function specify use File::Basename. It was always my understanding that use and require would not try to load a module a second time if it was already listed in %INC. A likely red herring here is that the main program does not actually import, call or otherwise reference the new library routine in the library module.
The key to the problem is (after a few hours of head scratching) that each routine calls File::Basename slightly differently which defines two seperate entries in %INC yet still loads the same module.
This all happens on a WinXP machine with Activestate 5.6.1. I haven't tried it on my Linux box yet. I'm guessing that this is a DOS/Win32 issue in that file names are not case sensative in that environment. Not groundbreaking, maybe, but an interesting gotcha none-the-less.
PJ
The key to the problem is (after a few hours of head scratching) that each routine calls File::Basename slightly differently which defines two seperate entries in %INC yet still loads the same module.
This all happens on a WinXP machine with Activestate 5.6.1. I haven't tried it on my Linux box yet. I'm guessing that this is a DOS/Win32 issue in that file names are not case sensative in that environment. Not groundbreaking, maybe, but an interesting gotcha none-the-less.
# stripped down test code #!/usr/local/ActivePerl-5.6/bin/perl use strict; use warnings; use diagnostics; use File::BaseName; printf("%-45s%-s\n",$_,$INC{$_}) foreach (sort keys %INC); package prob_func; sub secondfunc{ use File::Basename; return; } __OUTPUT__ #(relevent parts only) Subroutine fileparse_set_fstype redefined at C:/Program Files/Perl/lib/File/Basename.pm line 152 (#1) (W redefine) You redefined a subroutine. To suppress this warning +, say { no warnings; eval "sub name { ... }"; } Subroutine fileparse redefined at C:/Program Files/Perl/lib/File/Basen +ame.pm line 166 (#1) Subroutine basename redefined at C:/Program Files/Perl/lib/File/Basena +me.pm line 222 (#1) Subroutine dirname redefined at C:/Program Files/Perl/lib/File/Basenam +e.pm line 235 (#1) File/BaseName.pm C:/Program Files/Perl/lib +/File/BaseName.pm File/Basename.pm C:/Program Files/Perl/lib +/File/Basename.pm
Update:
I forget to include the package statement before the sub prob_func definition. The warning occurs either way but my original problem occurred in seperate namespacesUpdate:
Thanks for the great comments. The discussion did raise one or two other questions that I thought better moved to SOPW. Thanks again :o)PJ
use strict; use warnings; use diagnostics;
|
---|
Back to
Meditations