Tinasm
Tinasm

Reputation: 82

use Win32::Registry gives problems in Linux machine

My perl script must run on windows as well as Linux server. As the script runs, I have to update the registry for specific things. When I use "use Win32::Registry" It works fine on windows but on Linux it gives errors regardless of the following if statement.

if ($OS =~ /Windows/ )
{
use Win32::Registry;
...
...
}

In my view, perl loads "use" at compilation time and that must be the problem. What can I do so that Perl does not load use win 32 command when running on Linux?

I tried using

if ($OS =~ /Windows/ )
{
require Win32::Registry;
...
...
} 

with this, the script runs fine on both servers but it saves binary values in registry and not string value.

So how can I make the Perl script run on both servers and save string values in registry?

Thank you.

Upvotes: 1

Views: 293

Answers (1)

ikegami
ikegami

Reputation: 385915

use Foo;

is

BEGIN {
   require Foo;
   import Foo;
}

so use

BEGIN {
   if ($OS =~ /Windows/)
      require Win32::Registry;
      import Win32::Registry;
   }
}

or

use if $OS =~ /Windows/, 'Win32::Registry';

Upvotes: 6

Related Questions