Pregunta

Although I haven't seen any modules with same name but with different cases, but just for curiosity, I was trying to install Log::Log4perl and during installation I misspelled it 'Perl' in place of 'perl':

% cpan -i Log::Log4Perl 
Cannot install Log::Log4Perl, don't know what it is.

When I used correct name then things went well:

% cpan -i Log::Log4perl 

Same names but different cases can create conflicts. Is there any specific reason behind that?

¿Fue útil?

Solución

Because

use Foo::Bar;

would be ambiguous on case-sensitive file systems (Foo/Bar.pm? foo/bar.pm? FOO/BAR.pm? Foo/Bar.PM? etc), and it would require traversing the directory's contents to find the file's name. (Up to 9 directories per element of @INC would need traversing for Foo::Bar.)

Otros consejos

In Perl, modules loaded with use translated directly onto the file system. Something such as use Log::Log4perl translates into:

BEGIN {
    require 'Log/Log4perl.pm';
    Log::Log4perl->import;
    }

On a system that has a case sensitive file system, if the name is not exactly in the same case, it might as well not even exist. This is explained in the documentation for use and require. Different cases mean different names.

As such, when the cpan command translates a package name into a distribution, it uses the exact case you specify. The filesystem might be case insensitive, but inside Perl, the package names are still case sensitive. The literal case you enter is the one that Perl (and the cpan client) uses. If a package of that exact case isn't defined, the right things won't happen.

I consider this to be one of the major design decisions that hold Perl back and talked about it in my Frozen Perl 2011 keynote address.

Curiously, case insensitive filesystems lets you get away with it, as seen with the use seems to be case INSENSITIVE!! post on Perlmonks.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top