Beefy Boxes and Bandwidth Generously Provided by pair Networks
Syntactic Confectionery Delight
 
PerlMonks  

Re: Portability question: Is there something like '#ifdef' in Perl?

by Elian (Parson)
on Sep 29, 2003 at 17:09 UTC ( #295040=note: print w/replies, xml ) Need Help??


in reply to Portability question: Is there something like '#ifdef' in Perl?

Use $^O. It holds the name of the OS you're currently running on, and you can use it in conditional code all you like. It's the traditional way to do this sort of thing in perl. For conditional inclusion, throw things in a BEGIN block with require and import:
BEGIN { if ($^O eq 'Win32') { require Win32::Foo; import Win32::Foo; } elsif ($^O eq 'Linux') { require Linux::Foo; import Linux::Foo; } }
  • Comment on Re: Portability question: Is there something like '#ifdef' in Perl?
  • Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://295040]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (3)
As of 2021-08-05 01:32 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?
    My primary motivation for participating at PerlMonks is: (Choices in context)








    Results (44 votes). Check out past polls.

    Notices?