Beefy Boxes and Bandwidth Generously Provided by pair Networks
"be consistent"
 
PerlMonks  

Re: Windows pitfall: Subroutine redefined with use Modul

by dada (Chaplain)
on Oct 29, 2003 at 11:30 UTC ( #302977=note: print w/replies, xml ) Need Help??


in reply to Windows pitfall: Subroutine redefined with use Modul

yes, this is a nasty one indeed. as we all know, Perl is case sensitive, but the Windows filesystem not. what happens here is that Perl stores information about the modules it has loaded in its %INC hash, and it ends up having two entries for Subclass1. if you add these lines at the end of the bla.pl script:
use Data::Dumper; print Dumper(\%INC);
you'll see something like:
$VAR1 = { [...] 'subclass1.pm' => 'subclass1.pm', [...] 'Subclass1.pm' => 'Subclass1.pm', [...] };
so, the file is one but Perl sees (and loads) two modules. this could also pose serious problems with imported symbols, because when the case of the package name doesn't match, Perl loads the .pm file but doesn't export anything, as in:
use fIlE::SpEc qw(catfile); # note the wrong case $x = File::Spec->catfile('a', 'b', 'c'); # this works $x = catfile('a', 'b', 'c'); # this croaks
this is even more unobvious, because the error goes unnoticed until you try to use something that's exported from the module.

unfortunately, Perl can't possibly catch this sort of errors, so you have to watch your case. one possible solution (for the typo-prone individuals :-) could be to always cut & paste the use line from the SYNOPSIS found in the module documentation.

cheers,
Aldo

King of Laziness, Wizard of Impatience, Lord of Hubris

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://302977]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others contemplating the Monastery: (3)
As of 2023-04-01 11:55 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found

    Notices?