For Programmers: Free Programming Magazines  


Home > Archive > PERL Beginners > May 2006 > cross-platform Perl scripting...









You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

 

Author cross-platform Perl scripting...
sonamc@gmail.com

2006-05-25, 3:58 am

Hello - I wanted some advice writing a cross-platform Perl script...

I have a Perl script running a testing framework. It uses a CPAN module
(Proc::ProcessTable) which is only supported on Cygwin/Windows and
UNIX, but not on ActivePerl. Until now, it only ran on UNIX and Cygwin,
so this wasn't a problem.

Recently, it became necessary to support testing with the
Windows-specific SAMIE tool (http://samie.sourceforge.net/ ) which uses
Win32::* modules including Win32::GuiTest. ActivePerl supports Win32::*
without a problem, but not Proc::* modules. I tried installing Win32
modules on Cygwin but hit problems with Win32::GuiTest. The mailing
list for that module (http://groups.yahoo.com/group/perlguitest/) says
it isn't supported on Cygwin as it is compiled with Visual C++ but
Cygwin uses gcc.

My question: how can I make a unified cross platform Perl script expose
UNIX-specific functionality on UNIX, and Win32 functionality on
Windows? I tried implementing a conditional 'use' statement like
the one below, but it fails with a "Can't locate Win32/GuiTest.pm in
@INC".
-------------------------
if ($^O eq 'cygwin') {
use Proc::ProcessTable;
unix_specific_stuff();
} elsif ($^O =~ /MSWin/) {
use Win32::GuiTest;
windows_specific_stuff();
}
-------------------------

Is there a clean way to do this?

Sincerely,
Sonam Chauhan

sonamc@gmail.com

2006-05-25, 9:57 pm

Turns out that 'require' is what is needed: the following code gave
expected output under both Cygwin and Windows:

perl -e "if ($^O eq 'cygwin') {require Proc::ProcessTable; print 'found
cygwin'} elsif ($^O eq 'MSWin32') {require Win32::GuiTest; print 'found
windows'}"

Sponsored Links







Also available: Server administration forum archive | Web Design forum archive | Software forum archive | Hardware reviews archive

Copyright 2008 codecomments.com