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: Intermediate:
OS Specific 'use' statement

 



biplab
New User

Jun 3, 2011, 12:43 PM

Post #1 of 5 (1302 views)
OS Specific 'use' statement Can't Post

Hi All,

I have the following OS portability problem.

I want to 'use' a perl module in my code only if it is running under Windows. The module will not be available on Linux. But my code has to run on both Windows and Linux and I want the same code base to run on them.

In short I am looking for something like..

#if (OS is windows)
use WindowsModule.pm
#endif

Now statements like if($OSNAME eq 'Windows') does not work on this as I can not put the 'use' statement inside a regular 'if' condition.

If someone can think of a solution, can you please help me with this?

Biplab.


FishMonger
Veteran / Moderator

Jun 3, 2011, 4:37 PM

Post #2 of 5 (1299 views)
Re: [biplab] OS Specific 'use' statement [In reply to] Can't Post

Use 'require' instead of 'use' to load the module.

Or, you could put your if block inside a BEGIN block so that it is executed during the compilation phase.


rovf
Veteran

Jun 6, 2011, 12:46 AM

Post #3 of 5 (1197 views)
Re: [biplab] OS Specific 'use' statement [In reply to] Can't Post


Code
use if $^O eq 'MSWin32' , 'WindowsModule';



miller
User

Jun 6, 2011, 3:50 PM

Post #4 of 5 (1191 views)
Re: [biplab] OS Specific 'use' statement [In reply to] Can't Post

I suggest you read the documentation for use.

You'll find references to both methods of solving your problem that FishMonger and rovf have mentioned.

- Miller


(This post was edited by miller on Jun 6, 2011, 3:50 PM)


biplab
New User

Jun 8, 2011, 5:31 PM

Post #5 of 5 (1169 views)
Re: [miller] OS Specific 'use' statement [In reply to] Can't Post

Thanks a lot for the replies. All of these worked for me.

 
 


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

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