How to install .pm to run the perl script

10k views Asked by At

I am not a perl programmer. I have just installed perl and trying to run PERL script using it and it is giving me following error in debug mode:

Win32::OLE operating in debugging mode: _Unique => 1 at C:/strawberry/perl/vendor/lib/Win32/OLE/Lite.pm line 30. require Win32/OLE/Lite.pm called at C:/strawberry/perl/vendor/lib/Win32/OLE.pm line 48 require Win32/OLE.pm called at C:\Users\c_desaik\Desktop\pwrdb\offtarget\pwrdb.pl line 37 main::BEGIN() called at C:/strawberry/perl/vendor/lib/Win32/OLE/Lite.pm line 0 eval {...} called at C:/strawberry/perl/vendor/lib/Win32/OLE/Lite.pm line 0 main::(C:\Users\c_desaik\Desktop\pwrdb\offtarget\pwrdb.pl:53): 53:
my $prod_id = "QPSTAtmnServer.Application";

I hardly understand what it is trying to convey but sounds like I am missing OLE.pm file in my package library. SO I searched for it and I found following link:

http://cpansearch.perl.org/src/JDB/Win32-OLE-0.1711/lib/Win32/OLE.pm

Well, there is no link saying download there. I am not even sure how to add this source code to my library. Shall i just copy soruce code in notepad and save it as pm file or do something else?

Any help?

2

There are 2 answers

1
rutter On BEST ANSWER

I notice this sort of question comes up fairly often, so I'll type up a general answer that might serve as a rapid introduction for anyone.

So!

You're generally going to acquire modules in one of three ways:

From CPAN (most common)

CPAN provides a fairly thorough guide: How to install CPAN Perl modules. Depending on which Perl tools you have installed, you might try one of these on your command-line:

cpan install Some::Module
cpanm Some::Module

Since you're on Windows, I'll mention that Strawberry Perl should come with both tools installed.

Build-ready source (less common)

If you find a build-ready module on Github or some other open source repo, it may be available on CPAN anyway. If it's not, or if you want to install a development build, most mature modules will include quick instructions to clone and build. Check the project's README file!

Something like this is popular, after cloning:

perl Build.PL
./Build
./Build test
./Build install

The above is a suite of scripted operations provided by Module::Build, a popular mechanism for putting together modules for distribution.

Standalone Perl file (rare)

A lonesome module file will include no tests or install scripts. I'd be wary of trusting such modules, but it is possible to use them.

You may need to install various dependencies by either of the methods listed above. In my experience, most of these ad hoc modules don't expect to be "installed" per se, and can just be left in the root directory of your current project.

1
David W. On

A very, very important question:

  • Do you have Strawberry Perl, or
  • Do you have ActivePerl?

If you have Strawberry Perl, you will use a command line utility called cpan. For people who are use to GUIs, this can be a wee bit intimidating. First you have to run it, so it can configure itself. Much of the configuration is pretty automatic, and you can simply accept the defaults.

Once it's configured, you may have to run cpan a second time. The *.pm suffix stands for Perl Module, and you have to install the missing Perl module. Let's look at your error message once again:

Win32::OLE operating in debugging mode: _Unique => 1 at
C:/strawberry/perl/vendor/lib/Win32/OLE/Lite.pm line 30. require Win32/OLE/Lite.pm called at C:/strawberry/perl/vendor/lib/Win32/OLE.pm line 48 require Win32/OLE.pm called at C:\Users\c_desaik\Desktop\pwrdb\offtarget\pwrdb.pl line 37 main::BEGIN() called at C:/strawberry/perl/vendor/lib/Win32/OLE/Lite.pm line 0 eval {...} called at C:/strawberry/perl/vendor/lib/Win32/OLE/Lite.pm line 0 main:: (C:\Users\c_desaik\Desktop\pwrdb\offtarget\pwrdb.pl:53): 53: my $prod_id = `"QPSTAtmnServer.Application";

According to this, you're missing two modules: One is called Win32::OLE::Lite (from Win32/OLE/Lite.pm) and another Win32::OLE (from Win32/OLE)

You can go to http://search.cpan.com, type Win32::OLE::Lite into the search box, and you get the Win32::OLE CPAN page explaining how to use this module. It turns out Win32::OLE::Lite is a sub-module that's included in this module. You never address it separately.

In turn, it is likely that this module may depend upon other modules which can depend upon other modules. Don't worry, CPAN will take care of all the dependencies issues.

Now, to install this module, just type in the following command:

C:\> cpan install Win32::OLE

CPAN will chug away filling your screen with pages of output. Read it as it goes zooming by and commit it to memory because every word is absolutely important to remember. Okay, maybe not. However, I suggest you change the Windows Command Prompt Terminal Screen Buffer Height from 300 lines to 9999 lines incase there is something important.

When you do this, you'll see this:

CPAN: CPAN::SQLite loaded ok (v0.202)
CPAN: LWP::UserAgent loaded ok (v6.04)
CPAN: Time::HiRes loaded ok (v1.9725)
Fetching with LWP:
http://cpan.strawberryperl.com/authors/01mailrc.txt.gz
CPAN: YAML::XS loaded ok (v0.38)
Fetching with LWP:
http://cpan.strawberryperl.com/modules/02packages.details.txt.gz
Fetching with LWP:
http://cpan.strawberryperl.com/modules/03modlist.data.gz
Database was generated on Tue, 10 Sep 2013 19:27:08 GMT
Updating database file ...

And on and on...

You'll get warnings galore:

OLE.xs:5674:68: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
OLE.xs:5676:67: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
OLE.xs:5678:70: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
OLE.xs:5680:71: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
OLE.xs:5683:63: warning: deprecated conversion from string constant to 'char*' [-Wwrite-strings]
....

That's par for the course. As long as you don't see the dreaded word error, you're okay.

After compiling, you'll see a bunch of tests:

C:\perl\perl\bin\perl.exe "-MExtUtils::Command::MM" "-e" "test_harness(0, 'blib\lib',    'blib\arch')" t/*.t
t/1_nls.t ....... ok
t/2_variant.t ... ok
t/3_ole.t ....... ok
t/4_compat.t .... ok
t/5_unicode.t ... skipped: Unicode::String module not installed
t/6_event.t ..... ok
t/7_overload.t .. ok

ok and skipped are fine. With luck, you'll see:

All tests successful.
Files=7, Tests=112, 241 wallclock secs ( 0.09 usr +  0.03 sys =  0.13 CPU)

Next, comes the install, and you're done.

Type:

C:\> perldoc Win32::OLE

And, that should give you the Perl Doc on that module if that module is installed.

Now, run your program, and hope everything works.