3

I've installed a number of modules into my Strawberry Perl running on Windows XP, such as:

  • Regexp::Common
  • URI::Find::Schemeless

These libraries work fine in my perl code the first time directly after installing each module.

The problem is that every subsequent day I run my scripts they fail with the error:

Can't locate Regexp/Common.pm in @INC (@INC contains: C:/strawberry/perl/lib C:/ strawberry/perl/site/lib C:\strawberry\perl\vendor\lib .)

I have put all the appropriate paths into environment variables into Windows: PERL5LIB and others such as lib that were suggested on various other answers on stackoverflow and other wesites dealing with module installations. The scripts continue to fail unless I perform the following workaround that I figured out:

  1. Open the "edit the environment variables" window in Windows. ("My Computer" -> "Properties" -> "Advanced" tab -> "Environment Variables")
  2. Without adding or changing anything, click OK.
  3. Re-open any perl consoles that were already open or open a new perl window.
  4. Now the libraries are all found without issues.

Does anyone have an idea why this might be happening? I suspect it may be something specifically related to Windows/cmd or even my company's windows environment setup?

Any suggestions would be appreciated because it is an extremely annoying problem!

Jonathan Hall
  • 75,165
  • 16
  • 143
  • 189
Mandy
  • 1,449
  • 1
  • 11
  • 10
  • 3
    If this is a corporate computer, I wouldn't be surprised to find out there's a System Management Service script running daily to revert certain environment changes. If that's the case, then you may need to wrap your perl scripts in a batch file that explicitly sets these variables before invoking the perl script with `set PERL5LIB=whatever` etc. – Joe Z Nov 20 '13 at 04:45
  • What does `echo %PERL5LIB%` print when run in your Perl console? – cjm Nov 20 '13 at 07:26
  • @cjm - it says c:\strawberry\lib;c:\strawberry\c\lib;c:\strawberry\perl\lib;c:\strawberry\perl\site\lib;c:\strawberry\perl\vendor\lib which is where the libraries are. It says this after I do the little "workaround" too. It's really weird! – Mandy Nov 21 '13 at 01:40
  • What version of Windows are you using? I found reports of this happening at least on Vista (http://www.pcreview.co.uk/forums/windows-vista-forgets-my-path-environment-variable-reboot-t3191291.html), so it's not a completely unique problem, but I didn't find a solution. In any case, it's not a programming problem, so it doesn't belong on SO. – Mark Reed Nov 21 '13 at 14:32

1 Answers1

1

Windows does not clear the environment variables daily by default, therefore it's likely something in your corporate settings resetting the environment variables.

If this is the case, you have a few options:

  1. Get the network admins to modify the script so that it doesn't reset them (or includes the PERL5LIB directories you want to specify).
  2. Write another daily task, running after their daily task, which re-adds the variables on your local machine.
  3. Wrap your perl scripts with a Windows batch file, or run them with perl -I to specify the library at run time.
  4. Run your perl scripts from Cygwin bash or mingw bash, which won't use your computer's global environment variables.
Glitch Desire
  • 14,632
  • 7
  • 43
  • 55