http://www.perlmonks.org?node_id=387070

update In the YMMV vein, please see shay's Re: Building Perl with the free MSVC tools. The method below will apparently only work for some modules. I tried with DBI, DBD::SQLite, and Text::CSV_XS and they all work fine, so this method is useful for me regardless of what other modules it will or won't work with.

I got a new winXP box and wanted to be able to use perl (well, duh!) and to compile my own versions of CPAN modules without using cygqin bash or purchasing a compiler from Microsoft (not so duh, but not so hard either).

After attempting unsuccessfully to follow Building Perl with the free MSVC tools and through no fault of the excellent advice of corion++, intrepid++, demerphq++, I gave up and tried to just use the free tools to compile modules with activestate perl ... success!

Here's how:

Caution: these are humongous downloards (hundreds of mb). corion has a script which hopefully he'll share to wget just the needed portions. But here's how I did it with the full (*free* as in beer) downloads:

  1. Download and install Microsoft Visual C++ Toolkit 2003
  2. Download and install Microsoft SDK Platform Update
  3. Download and install .NET redistributable
  4. Download and install .NET SDK
  5. Set environment to recognize the bin/lib/inc dirs for all of those (update these assume the default install paths, but see demerphq's points below for reasons you might want to use short path names instead and for alternate ways to set the environment):
    @echo off
    set MSVC=C:\Program Files\Microsoft Visual C++ Toolkit 2003
    set MSSDK=C:\Program Files\Microsoft Visual Studio .NET 2003\Vc7
    set Mstools=C:\Program Files\Microsoft SDK
    
    set INCLUDE=%MSVC%\include;%MSSDK%\include;%Mstools%\include
    set LIB=%MSVC%\lib;%MSSDK%\lib;%Mstools%\Lib;
    set PATH=%MSVC%\bin;%MSSDK%\bin;%Mstools%\Bin;%Mstools%\Bin\WinNT;%PATH%
    
  6. Download and install the latest (*free as in speech*) perl binary

  7. Download and install (*free as in speech*) cygwin (or just grab the needed tools - gzip, tar, cat, etc.)

  8. You can now use PPM or CPAN.pm or CPANPLUS or nmake to compile and install (many) CPAN modules ... Enjoy!
update : made URLs into links per bart's suggestion