granric
granric

Reputation: 21

Perl module run under Linux and Win32

I've a perl module which needs to run within both Win32 and Linux OSes. This module employs Win32::Process::List to avoid concurrency issues with a 3rd party application under Win32, and has no equivalent requirement when run under Linux.

So far, I've managed to have two copies of the same module, with Win32-specific stuff commented out for the Linux version - and I'm obviously not happy with this error-prone approach.

It is clear that win-specific stuff does not "make install" in Linux. I've tried a softer approach in my code with require Win32::Process::List; instead of use Win32::Process::List;, the former giving the advantage of passing perl -c mymodule - however still failing in regular use.

Thus my question: apart from mantaining two distinct code bases, is there a more robust way to approach such situations?

Upvotes: 2

Views: 1180

Answers (1)

Borodin
Borodin

Reputation: 126722

How about using the if module, which allows you to use a module according to compile-time conditions.

use if $^O eq 'MSWin32', 'Win32::Process::List';

The $^O built-in variable gives the name of the operating system, and is always MSWin32 for any Windows system.

Upvotes: 4

Related Questions