Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

using modules based on platform

Status
Not open for further replies.

arcnon

Programmer
Aug 12, 2003
242
US
what is the best stradigy to use modules and the like based on platform?

ie
use Term::ANSIColor qw:)constants);
unix & os x

use Win32::Console::ANSI;
windows also requires this to display ansii color

I am using Config & $^O to determine the platform and use ifs to use certain platform specific modules.

I am sure that there must be a better cleaner way.
Either a setup script that hard codes it to a specific platform or something that I haven't thought of.

what do you guys think?
 
Hi,

In the past I've done it exactly as you describe.

You could, as you say, write a setup script that creates a platform specific Perl script based on what platform it finds itself running on. I can't think why you'd do that though, it just adds complexity.

Mike

shows ways to help with Tsunami Relief.

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Multi-platform support makes Perl more powerful and portable than many other languages..

I remember that I did not believe the first time that I was using Tk under windows and when I copy the script to an Unix Serves it works as a champion just changing some libraries and paths.

As Mike say adding "this feature" you are adding more complexity and extra-hard-work to your script. But, probably you are doing it for an specific purpose.

Things like these are valid:

($^O =~ /Win/ ) ? system("notepad.exe $DateTime") : system( "/usr/dt/bin/dtpad -standAlone -noReadOnlyWarning -viewOnly $DateTime \&" );

$SCRIPTPATH = "/m/home/dmazzini" if ($^O !~ /Win/ );

Cheers!





dmazzini
GSM System and Telecomm Consultant

 
The trick to making Mult-platform code work for you is, imho, to push the platform dependant code down into re-usable modules which are then called by your application scripts.

So in dmazzini's example above the code that evaluates which platform it is running on "($^O =~ /Win/ ) ?" would be in a module.

Mike

shows ways to help with Tsunami Relief.

You cannot really appreciate Dilbert unless you've read it in the
original Klingon.

Want great answers to your Tek-Tips questions? Have a look at faq219-2884
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top