How to write cross-platform perl code
A perl script which would include di开发者_JAVA技巧fferent modules for both Windows and Linux, In order to make it cross-platform, I want someway to implement it, just like in C++:
#if _WIN32
//...
#else
//...
#endif
if, $^O
:
use if $^O eq 'MSWin32', Win32::Console::ANSI::;
Alternatively,
use Win32::Console::ANSI ();
is equivalent to
BEGIN {
require Win32::Console::ANSI;
}
so you could also use
BEGIN {
require Win32::Console::ANSI
if $^O eq 'MSWin32';
}
精彩评论