How do I conditionally use a Perl module only if I'm on Windows?

后端 未结 4 749
醉话见心
醉话见心 2021-02-14 22:43

The following Perl code ..

if ($^O eq \"MSWin32\") {
  use Win32;                                                                                                         


        
4条回答
  •  北海茫月
    2021-02-14 23:29

    As a shortcut for the sequence:

    BEGIN {
        if ($^O eq "MSWin32")
        {
            require Win32;
            Win32::->import();  # or ...->import( your-args ); if you passed import arguments to use Win32
        }
    }
    

    you can use the if pragma:

    use if $^O eq "MSWin32", "Win32";  # or ..."Win32", your-args;
    

提交回复
热议问题