How to write cross-platform perl code

半世苍凉 提交于 2019-12-08 07:56:56

问题


A perl script which would include different 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

回答1:


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';
}


来源:https://stackoverflow.com/questions/7382833/how-to-write-cross-platform-perl-code

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!