1

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.

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
cppcoder
  • 22,227
  • 6
  • 56
  • 81
  • That's not a problem, both work for Perl on Windows (assuming the backslashes (windows style) are properly escaped - you should actually consider only using forward slashes, less chances of getting problems). – Mat May 26 '12 at 10:37
  • The question may be about directories, but your problem is that your module MyGengo.pm is not anywhere your script can see it, which is in either of the three directories listed in `@INC`. – TLP May 26 '12 at 12:18
  • @TLP The module is present in this dir `C:\Perl\lib\MyGengo\mygengo-api\nheinric-mygengo-perl-new-ce194df\mygengo` – cppcoder May 26 '12 at 13:14
  • @cppcoder With the statement `use MyGengo`, perl will look for `c:/perl/lib/MyGengo.pm`. Directories are denoted with double colons, so that `use MyGengo::Foo` will be found in `c:/perl/lib/MyGengo/Foo.pm`. – TLP May 26 '12 at 14:15

1 Answers1

4

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.

Greg Bacon
  • 134,834
  • 32
  • 188
  • 245
  • The module is present in `C:\Perl\lib\MyGengo\mygengo-api\nheinric-mygengo-perl-new-ce194df\mygengo`. So perl should find it right? – cppcoder May 26 '12 at 13:17
  • Is that the directory that contains `MyGengo.pm`? If not, where is it? Are you using [myGengo-perl](http://github.com/myGengo/mygengo-perl)? Complete documentation of module resolution is in the [perlfunc documentation on `require`](http://perldoc.perl.org/functions/require.html) – Greg Bacon May 26 '12 at 13:45
  • Yes, The dir I pasted has the `MyGengo.pm`. – cppcoder May 26 '12 at 13:46
  • I have downloaded the library and manually copied in the `C:\Perl\lib\MyGengo` directory. – cppcoder May 26 '12 at 14:03
  • Yes, I copied the `.pm` from the source directory and placed it in `C:\Perl\lib` – cppcoder May 26 '12 at 14:07
  • Can you tell me the difference between locations `C:\Perl\lib` & `C:\Perl\site\lib` in your answer? – cppcoder May 26 '12 at 14:13
  • The difference is mostly conventional. `C:\Perl\site\lib` is your local site's library. You control it. `C:\Perl\lib` is your perl installation's library. If you uninstall ActivePerl, for example, your site library will be left untouched. – Greg Bacon May 26 '12 at 14:17