CGI/Perl Guide | Learning Center | Forums | Advertise | Login
Site Search: in

  Main Index MAIN
INDEX
Search Posts SEARCH
POSTS
Who's Online WHO'S
ONLINE
Log in LOG
IN

Home: Perl Programming Help: Beginner:
'use Win32' problem on linux

 



sophie
Novice

Aug 27, 2004, 6:45 AM

Post #1 of 6 (1336 views)
'use Win32' problem on linux Can't Post

Hi everyone,

I am writing a perl script to handle both windows and linux platform. I hope when the platform is windows then use win32 module. My code like below.

if ($^O == 'MSWin32') { use Win32; }

but when I run my script on linux, I got compile error "Can't locate Win32.pm in @INC ..."

Please help! Thanks!


davorg
Thaumaturge / Moderator

Aug 27, 2004, 7:26 AM

Post #2 of 6 (1335 views)
Re: [sophie] 'use Win32' problem on linux [In reply to] Can't Post

That's because all "use" statements get executed at compile-time - long before any of the code is executed.

The way to get round it is to defer the "use" until runtime with "eval".


Code
if ($^O eq 'MSWin32') { eval require Win32 }


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


sophie
Novice

Aug 27, 2004, 8:00 AM

Post #3 of 6 (1334 views)
Re: [davorg] 'use Win32' problem on linux [In reply to] Can't Post

But if I do that way. Functions in Win32 don't work. It seems the functions and constant symbles aren't exported properly.


davorg
Thaumaturge / Moderator

Aug 27, 2004, 8:50 AM

Post #4 of 6 (1333 views)
Re: [sophie] 'use Win32' problem on linux [In reply to] Can't Post

Bah. I wrote "require" when I meant "use" :(


Code
if ($^O eq 'MSWin32') { eval "use Win32" }


--
Dave Cross, Perl Hacker, Trainer and Writer
http://www.dave.org.uk/
Get more help at Perl Monks


sophie
Novice

Aug 27, 2004, 9:20 AM

Post #5 of 6 (1332 views)
Re: [davorg] 'use Win32' problem on linux [In reply to] Can't Post

Thanks for your reply. But the constant symbles still seem not be exported correctly. e.g. I use Win32::Daemon module, and run the following script on windows.

if ($^O eq 'MSWin32') { eval "use Win32::Daemon;" }

...

Win32::Daemon::State(SERVICE_RUNNING);

...

I got error message "argument SERVICE_RUNNING isn't numeric in subroutine entry at test.pl line 20.


sophie
Novice

Sep 3, 2004, 2:37 AM

Post #6 of 6 (1320 views)
Re: [sophie] 'use Win32' problem on linux [In reply to] Can't Post

I solved my problem using eval of course.

e.g. Win32::Daemon::State(eval 'SERVICE_RUNNING');


Thanks

 
 


Search for (options) Powered by Gossamer Forum v.1.2.0

Web Applications & Managed Hosting Powered by Gossamer Threads
Visit our Mailing List Archives