perl Conditional compile - Running Win32 library calls on AIX 
Author Message
 perl Conditional compile - Running Win32 library calls on AIX

Fellow Perl Experts,

I need a code snippette to run both on AIX and NT.
the "use Win32::Registry" runs only on NT and causes
error on AIX.  Is there a way to write a program that runs
both on NT and AIX?  I use "eval 'use Win32::Registry' if $isNT;"
statement, but this is producing unexpected results in my program..


this problem..

Many thanks,
Faithful

if (-d "c:\\") {$isNT=1;}  
if ($isNT) {&check_registry;}

sub check_registry
{
  eval 'use Win32::Registry' if $isNT;
  my $Register = "SYSTEM\\CurrentControlSet\\Services\\myservice";
  my $RegType, $RegValue, $RegKey, $value;
  my  %values;
  $HKEY_LOCAL_MACHINE->Open($Register,$hkey);
  $hkey->GetValues(\%values);
  $hkey->SetValueEx("Start",0,&REG_DWORD,2);  
 $hkey->SetValueEx("Start",0,REG_DWORD,2);
  $hkey->Close();

Quote:
}



Fri, 25 Nov 2005 20:29:49 GMT  
 perl Conditional compile - Running Win32 library calls on AIX
Hi Kir

Quote:
> I need a code snippette to run both on AIX and NT.
> the "use Win32::Registry" runs only on NT and causes
> error on AIX.  Is there a way to write a program that runs
> both on NT and AIX?  I use "eval 'use Win32::Registry' if $isNT;"
> statement, but this is producing unexpected results in my program..


> this problem..

> Many thanks,
> Faithful

> if (-d "c:\\") {$isNT=1;}

First off, in order to load specific modules depending on the OS I use
something like this:

use warnings;
use strict;

BEGIN {
    if ( $^O =~ /MSWin32/ ) {
        require Win32::Registry;
        print "Running under WNT\n";

    }
    else {

        print "Not running under NT\n";

    }

Quote:
}

This small script will run under unix as well an NT.

Quote:
> if ($isNT) {&check_registry;}

Then
if ($^O =~/MSWin32/)  {
   check_registry();

Quote:
}

> sub check_registry
> {
>   eval 'use Win32::Registry' if $isNT;

No need for the above line since it is already loaded;

Quote:
>   my $Register = "SYSTEM\\CurrentControlSet\\Services\\myservice";
>   my $RegType, $RegValue, $RegKey, $value;
>   my  %values;
>   $HKEY_LOCAL_MACHINE->Open($Register,$hkey);
>   $hkey->GetValues(\%values);
>   $hkey->SetValueEx("Start",0,&REG_DWORD,2);
>  $hkey->SetValueEx("Start",0,REG_DWORD,2);
>   $hkey->Close();
> }

I hope this helps!!

Mothra



Fri, 25 Nov 2005 21:27:19 GMT  
 
 [ 2 post ] 

 Relevant Pages 

1. calling C libraries from Perl and calling Perl libraries from C

2. calling C libraries from Perl and calling Perl libraries from C

3. calling C libraries from Perl and calling Perl libraries from C

4. Where to Get Compiled Perl Module to run on AIX 4.2/4.3

5. Perl calling compiled C library (.lib)

6. Problems running perl script with call to Win32::AdminMisc

7. Problems running perl script with call to Win32::AdminMisc

8. Compiling Perl5.001m on AIX 4.1.3 using AIX C

9. compiling perl for ibm aix 5.1

10. make test error in compiling Perl under AIX 4.2.1

11. Compiling Perl 5.001m undex AIX 4.1 -- Help!

12. compile perl on aix

 

 
Powered by phpBB® Forum Software