I am using ActiveState perl with Komodo Edit. I am getting the following error.

Can't locate MyGengo.pm in @INC (@INC contains: C:/Perl/site/lib C:/Perl/lib .) 
at D:\oDesk\MyGengo Integration\sample line 6.

Why is the interpreter looking in C:/Perl/lib instead of C:\Perl\lib? Doesn’t it know that it is Windows and not Linux?

EDIT

I resolved the problem by copying the .pm file in C:\Perl\lib directory. I think, the issue happened since this module was manually downloaded. PPM install would copy the .pm file to the lib directory.

有帮助吗?

解决方案

As far as Windows is concerned, C:/Perl/lib and C:\Perl\lib are the same directory.

The perlport documentation notes (emphasis added)

DOS and Derivatives

Perl has long been ported to Intel-style microcomputers running under systems like PC-DOS, MS-DOS, OS/2, and most Windows platforms you can bring yourself to mention (except for Windows CE, if you count that). Users familiar with COMMAND.COM or CMD.EXE style shells should be aware that each of these file specifications may have subtle differences:

my $filespec0 = "c:/foo/bar/file.txt";
my $filespec1 = "c:\\foo\\bar\\file.txt";
my $filespec2 = 'c:\foo\bar\file.txt';
my $filespec3 = 'c:\\foo\\bar\\file.txt';

System calls accept either / or \ as the path separator. However, many command-line utilities of DOS vintage treat / as the option prefix, so may get confused by filenames containing /. Aside from calling any external programs, / will work just fine, and probably better, as it is more consistent with popular usage, and avoids the problem of remembering what to backwhack and what not to.

Your comment shows that you’re using mygengo-perl-new but have it installed in C:\Perl\lib\MyGengo\mygengo-api\nheinric-mygengo-perl-new-ce194df\mygengo. This is an unusual location to install the module. The way the module is written, it expects mygengo.pm to be in one of the directories named in @INC. Client code then pulls it in with

use mygengo;

My suggestion is to move mygengo.pm from C:\Perl\lib\MyGengo\mygengo-api\nheinric-mygengo-perl-new-ce194df\mygengo to C:\Perl\site\lib.

As an alternative if you are using mygengo as part of another package that you’re developing, you could drop mygengo in your source tree, perhaps as a git submodule. Don’t forget to add use lib 'mygengo'; if you do it this way.

For full details, read about the @INC search process in the perlfunc documentation on require and the extra semantics for modules via use.

General advice on slashes versus backslashes

Even if your code will run on Windows only, prefer using forward-slash as the separator in hardcoded paths. Backslash is an escape character in the Perl language, so you have to think more carefully about it. In double-quoted strings, you have to remember to escape the escape character to get its ordinary meaning, e.g.,

# my $dir = "C:\Perl\lib";  # oops, $path would be 'C:Perlib'

$dir = "C:\\Perl\\lib";

The situation can be a little nicer inside single-quoted strings. Setting $dir as in

$dir = 'C:\Perl\lib';

does what you expect, but say you want $dir to have a trailing slash.

$dir = 'C:\Perl\lib\';

Now you have a syntax error.

Can't find string terminator "'" anywhere before EOF at dirstuff line n.

You may want to interpolate another value into $dir.

$dir = 'C:\Perl\lib\$module';  # nope

Oh yeah, you need double-quotes for interpolation.

$dir = "C:\Perl\lib\$module";  # still not right

After headscratching and debugging

$dir = "C:\\Perl\\lib\\$module";  # finally

Backslash is therefore more mistake-prone and a maintenance irritant. Forward slash is an ordinary character inside both single- and double-quoted strings, so it almost always means what you expect.

As perlport notes, the Windows command shell treats forward slash as introducing options and backslash as path separators. If you cannot avoid the shell, then you may be forced to deal with backslashes.

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top