loading a module dependant on the OS

G

Guest

I have a Perl script which runs under Windows and uses the module
Win32::process, I now have a need to run this on Linux.

I can do produce two scripts on for each platform, which would be a pain to
maintane.

My question being how can I have a script on Linus that has

use Win32::process;

since this module does not exist I get a compilation error. I thought I
could use the $^O variable but my little knowledge fails to supply the
answer.

I assume this is a common problem so will have an answer. If you can point
me in the direction of a README or HOW_TO document I would be greatful.

Richard.
 
B

Brian McCauley

use Win32::process;

since this module does not exist I get a compilation error. I thought I
could use the $^O variable but my little knowledge fails to supply the
answer.

Since you have a question about use please read at least the first
paragraph of:

perldoc -f use

Write the "use" out long-hand and then apply the knowledge already
have. That should supply the answer.

Surely this should be in the FAQ!

--
\\ ( )
. _\\__[oo
.__/ \\ /\@
. l___\\
# ll l\\
###LL LL\\
 
R

Rohan Romanus Almeida

use Win32::process;

since this module does not exist I get a compilation error. I thought I
could use the $^O variable but my little knowledge fails to supply the
answer.

You can do an "eval" before the use.

Look at this example:
<code>
$useReadKey = 0;
eval q/use Term::ReadKey/;
if (!$@) {
# Term-ReadKey module is installed
$useReadKey = 1;
}
</code>
 
G

Gunnar Hjalmarsson

use Win32::process;

since this module does not exist I get a compilation error. I
thought I could use the $^O variable

You can:

BEGIN { require Win32::process if $^O eq 'MSWin32' }

/ Gunnar
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,774
Messages
2,569,596
Members
45,135
Latest member
VeronaShap
Top